推送 UIViewController 时发生内存泄漏
每次我推送一个新的视图控制器时,它都会增加大约 3MB。 TestVC是一种全新的VC,具有一种推送新版本VC的方法。
UIViewController *vc = [[TestVC alloc] initWithNibName:nibName bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
当我 popviewController 时,它不会释放任何内存(观看活动监视器)。
[self.navigationController popViewControllerAnimated: YES];
因此,当我添加浏览应用程序(大约 60 个不同的页面)时,内存会不断积累。 initWithNibName 需要一些特殊的东西吗?当我弹出时,我需要以某种方式释放笔尖吗?
Each time I push a new viewcontroller, it adds about 3MB. TestVC is a brand new VC with one method for pushing a new version of the VC.
UIViewController *vc = [[TestVC alloc] initWithNibName:nibName bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
When I popviewController, it doesn't release any memory (watching activity monitor).
[self.navigationController popViewControllerAnimated: YES];
So, as I add navigate through the app (about 60 different pages), memory keeps building up. Does initWithNibName need something special. When I pop, do I need to release the nib somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最可能的问题是在
-[TestVC dealloc]
中释放
某些内容失败。我会首先通过检查来评估该方法。如果找不到问题,请使用 Instruments 中的 Leaks 工具来查找过度保留的特定内容。如果 Leaks 没有找到它,则使用 Instruments 中的 heapshot 工具来查看正在分配的内容。这么大的东西,应该很容易找到。 使用 Heapshot 的快速概述你的面包。The most likely problem is a failure to
release
something in-[TestVC dealloc]
. I would evaluate that method by inspection first. If you can't find the problem, use the Leaks instrument in Instruments to find what particular thing is being over-retained. If Leaks doesn't find it, then use the heapshot tool in Instruments to see what's being allocated. With something so large, it should be easy to find. There's a quick overview of using Heapshot on Use Your Loaf.