为什么这段代码会产生内存泄漏?
Xcode 中的 Leaks Instrument 向我显示了内存泄漏。我已经评论了 Leaks 所抱怨的受影响的线路。但我在内存管理中没有看到错误...
- (void)setupViewController {
MyViewController *myVC = [[MyViewController alloc] init];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
myVC.tabBarItem = tbi; // LEAK: 128 bytes
self.myViewController = myVC;
[myVC release];
[tbi release];
}
我的意思是... tbi 和 myVC 最后被释放,并且 alloc 是平衡的。那么出了什么问题呢?我不明白。
The Leaks Instrument in Xcode shows me an memory leak here. I have commented the affected line which Leaks is complaining about. But I see no error in my memory management...
- (void)setupViewController {
MyViewController *myVC = [[MyViewController alloc] init];
UITabBarItem *tbi = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
myVC.tabBarItem = tbi; // LEAK: 128 bytes
self.myViewController = myVC;
[myVC release];
[tbi release];
}
I mean... tbi and myVC IS released at the end, and the alloc IS balanced. So what's wrong? I don't get it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 MyVc.tabBarItem 已设置,则它指向的任何内容都可能无法正确释放,从而导致泄漏。
if MyVc.tabBarItem is already set, whatever it's pointing at may not be deallocated properly, causing a leak.
它只是表明以下至少一项陈述是正确的:
事实上,两者都是正确的。
It just goes to show that at least one of the following statements is true:
In fact, both are true.