should variable be released or not? iphone-sdk
Posted
by psebos
on Stack Overflow
See other posts from Stack Overflow
or by psebos
Published on 2010-03-22T11:52:40Z
Indexed on
2010/03/22
12:01 UTC
Read the original article
Hit count: 346
Hi, In the following piece of code (from a book) data is an NSDictionary *data; defined in the header (no property).
In the viewDidLoad of the controller the following occurs:
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *keys = [NSArray arrayWithObjects:@"home", @"work", nil];
NSArray *homeDVDs = [NSArray arrayWithObjects:@"Thomas the Builder", nil];
NSArray *workDVDs = [NSArray arrayWithObjects:@"Intro to Blender", nil];
NSArray *values = [NSArray arrayWithObjects:homeDVDs, workDVDs, nil];
data = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
}
Since I am really new to objective-c can someone explain to me why I do not have to retain the variables keys,homeDVDs,workDVDs and values prior exiting the function? I would expect prior the data allocation something like:
[keys retain];
[homeDVDs retain];
[workDVDs retain];
[values retain];
or not? Does InitWithObjects copies (recursively) all objects into a new table?
Assuming we did not have the last line (data allocation) should we release all the NSArrays prior exiting the function (or we could safely assumed that all NSArrays will be autoreleased since there is no alloc for each one?)
Thanks!!!!
© Stack Overflow or respective owner