开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜