i am using this a1 = [[NSMutableArray alloc] init]; now what should be the best way to release a1
right now i am releasing in dealloc()
i am allocation a1 in viewdidload() and displaying 10 images there
i am using this a1 = [[NSMutableArray alloc] init]; now what should be the best way to release a1
right now i am releasing in dealloc()
i am allocation a1 in viewdidload() and displaying 10 images there
Read this:
http://inessential.com/2010/06/28/how_i_manage_memory
and then this:
http://inessential.com/2010/06/28/follow_up_to_memory_management_thing
A basic example would be this:
// get the party started
NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
// as an example, just copy some user defaults into the mutable array
tmpArray = [[userDefaults objectForKey:@"UserDefaultsExample"] mutableCopy];
// do something here with tmpArray (i.e. if ([tmpArray count] == 0) //do something)
// once you are done with tmpArray, go ahead and release it
[tmpArray release];
For your case, you'd want to release the array once you are finished with it (i.e. at the end of viewDidLoad
is probably a safe bet as long as you truly are finished with it). If you do it this way, you don't need to create an NSMutableArray object in your .h file, synthesize it and release in dealloc. Instead, you just create a temporary one like I did above and release it when you're done showing the images from it.