开发者

Retain memory leak in iphone menuitem

开发者 https://www.devze.com 2023-04-09 03:14 出处:网络
How to solve memory leak in this: NSArray *keyboard = [[[NSDictionary alloc] initW开发者_StackOverflow中文版ithContentsOfFile:menuPath] objectForKey:@\"Menu\"];

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]; 
0

精彩评论

暂无评论...
验证码 换一张
取 消