Memory leak using NSMutableArray in RootViewController called from App Delegate
Posted
by Lauren Quantrell
on Stack Overflow
See other posts from Stack Overflow
or by Lauren Quantrell
Published on 2010-06-16T14:13:11Z
Indexed on
2010/06/16
14:22 UTC
Read the original article
Hit count: 521
I've written code to restore the state of my app, but there's a memory leak in the NSMutableArray. I'm new to Xcode so I apologize if this is something trivial I have overlooked. Any help is appreciated. lq
AppDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[rootViewController restoreState];
}
RootViewController.h
@interface rootViewController : UIViewController {
NSMutableArray *offendingNSMutableArray;
}
@property (nonatomic, retain) NSMutableArray *offendingNSMutableArray;
RootViewController.m
@synthesize offendingNSMutableArray;
- (void)restoreState {
// Gets an array stored in the user defaults plist
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
self.offendingNSMutableArray = [[NSMutableArray alloc]
initWithArray:[userDefaults objectForKey:kArrayValue]];
}
- (void)viewDidUnload {
self.offendingNSMutableArray = nil;
}
- (void)dealloc {
[offendingNSMutableArray release];
}
© Stack Overflow or respective owner