在iphone menuitem中保留内存泄漏

时间:2011-09-28 06:22:57

标签: iphone memory memory-leaks retain

如何解决内存泄漏:

NSArray *keyboard = [[[NSDictionary alloc] initWithContentsOfFile:menuPath] objectForKey:@"Menu"];
[self setMenuItems:keyboard];
[keyboard release];

setMenuItems在头文件中定义。

@property (nonatomic,retain) NSArray *menuItems;

2 个答案:

答案 0 :(得分:1)

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:menuPath]; 
self.menuItems = [dict objectForKey:@"Menu"]; 
[dict release];

在你的dealloc方法中

- (void)dealloc
{
    [menuItems release], menuItems = nil;
}

答案 1 :(得分:-1)

在dealloc方法

- (void)dealloc
{
self.menuItems = nil;
[super dealloc];
}

NSArray *keyboard = [[[NSDictionary alloc] initWithContentsOfFile:menuPath] objectForKey:@"Menu"];
self.menuItems = keyboard; 
[keyboard release];