如何释放 NSMutableDictionary
我从 viewDidLoad 调用 createTableData。我不明白的是我正在为 NSMutableDictionary 进行分配,但我不明白为什么该对象没有从内存中释放 - 尽管释放了。 我确实看到内存泄漏,泄漏似乎指向这一段代码。 有人可以给我指出一个网址,我可以在其中阅读/理解我应该做什么和我正在做什么吗?我似乎看不出我哪里出了问题。
- (void)createTableData {
NSMutableArray *toolList;
toolList=[[NSMutableArray alloc] init];
[toolList addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Some title",@"name",
@"1",@"whatViewController",
@"",@"url",
@"some_icon.jpg",@"picture",
@"some detail text",@"detailText",nil]];
toolData=[[NSMutableArray alloc] initWithObjects:toolList,nil];
[toolList release];
}
- (void)dealloc {
[toolData release];
[super dealloc];
}
I call createTableData from viewDidLoad. What I don't understand is I'm doing an alloc for a NSMutableDictionary but I don't understand why that object is not released from memory-despite the release.
I do see memory leaks and Leaks seems to point at this section of code.
Can someone point me to a url where I might be able to read/understand what I should be doing versus what I am doing? I just can't seem to see where I've gone wrong here.
- (void)createTableData {
NSMutableArray *toolList;
toolList=[[NSMutableArray alloc] init];
[toolList addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Some title",@"name",
@"1",@"whatViewController",
@"",@"url",
@"some_icon.jpg",@"picture",
@"some detail text",@"detailText",nil]];
toolData=[[NSMutableArray alloc] initWithObjects:toolList,nil];
[toolList release];
}
- (void)dealloc {
[toolData release];
[super dealloc];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这一行中,您将 NSMutableDictionary 对象添加到数组中并且不释放它。正确的代码是(使用已经返回自动释放对象的类方法):
或显式自动释放临时字典:
In this line your add NSMutableDictionary object to array and not releasing it. Correct code would be (using class method that already returns autoreleased object):
or explicitly autorelease your temporary dictionary: