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 是平衡的。那么出了什么问题呢?我不明白。
最佳答案
如果 MyVc.tabBarItem 已设置,则它指向的任何内容都可能无法正确释放,从而导致泄漏。
关于iphone - 为什么这段代码会产生内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2268692/