Retain memory leak in iphone menuitem
How to solve memory leak in this:
NSArray *keyboard = [[[NSDictionary alloc] initW开发者_StackOverflow中文版ithContentsOfFile:menuPath] objectForKey:@"Menu"];
[self setMenuItems:keyboard];
[keyboard release];
setMenuItems is defined in header file.
@property (nonatomic,retain) NSArray *menuItems;
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:menuPath];
self.menuItems = [dict objectForKey:@"Menu"];
[dict release];
And in your dealloc method
- (void)dealloc
{
[menuItems release], menuItems = nil;
}
In dealloc method
- (void)dealloc
{
self.menuItems = nil;
[super dealloc];
}
NSArray *keyboard = [[[NSDictionary alloc] initWithContentsOfFile:menuPath] objectForKey:@"Menu"];
self.menuItems = keyboard;
[keyboard release];
精彩评论