i’m a little bit confused with memory management in view controllers.
Lets say i have header file like this:
@interface MyController : UIViewController {
NSMutableArray *data;
}
@property (nonatomic, retain) NSMutableArray *data;
@end
and .m file looks like that:
@implementation MyController
@synthesize data;
- (void)dealloc
{
[self.data release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.data == nil)
self.data = [[NSMutableArray alloc] init];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[self.data release];
self.data = nil;
}
Is that ok from the correct memory management point of view? Will that work after dealloc via Memory Warning? How You do that in your apps?
Thanks for your answers 😉
While the
alloc-retaincalls balance out inviewDidLoadandviewDidUnloadand should prove no problem memory-wise, it would be cleaner to take ownership only once and relinquishing it once rather than twice.and