如何解决内存泄漏:
NSArray *keyboard = [[[NSDictionary alloc] initWithContentsOfFile:menuPath] objectForKey:@"Menu"];
[self setMenuItems:keyboard];
[keyboard release];
setMenuItems在头文件中定义。
@property (nonatomic,retain) NSArray *menuItems;
答案 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];