释放内存解除模态视图控制器
我的应用程序由一个带有 10 个按钮的父视图控制器组成,这些按钮都通向 10 个不同的模式视图,所有这些视图都包含相当多的内容。该应用程序在模拟器上完美运行,但在实际设备上,它收到许多内存警告,有时甚至崩溃。
当使用分配工具在模拟器上测试应用程序时,我注意到当我呈现或关闭模态视图时,内存会增加并且不会减少。我什至可以一遍又一遍地呈现和消除同一个内容,并且记忆会不断增加。
我的模态视图代码如下所示:
MyViewController *controller = [[MyViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
然后,为了解除:
[self dismissModalViewControllerAnimated:YES];
我在模态视图控制器的 dealloc 方法中释放了许多按钮和图像视图。当我分析程序时没有任何问题,没有错误或警告。
My app consists of a parent view controller with 10 buttons that all lead to 10 different modal views, all of which have have quite a bit of content to them. The app runs perfectly on the simulator, but on the actual device, it receives many memory warnings, and sometimes crashes.
When testing the app on the simulator with the allocations instrument, I notice that the memory counts up and does not go down when I present or dismiss the modal views. I can even present and dismiss the same one over and over and the memory continually counts up.
My code for the modal view looks like this:
MyViewController *controller = [[MyViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
Then for dismissing:
[self dismissModalViewControllerAnimated:YES];
I am releasing many buttons and image views in the dealloc method of the modal view controller. There are no problems when I analyze the program, no errors or warnings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 6.0 后该方法已被弃用。
请尝试使用此线程 [1]。
[1]:单击 uibutton 时关闭弹出窗口“此链接”。
This method is depreciated after iOS 6.0.
Try this thread[1] instead.
[1]: Dismiss popover when clicking a uibutton "this link".