PresentModalViewController 没有被释放

发布于 2024-11-30 14:30:23 字数 331 浏览 6 评论 0原文

我试图呈现一个自定义视图控制器,其中自定义视图从分离的 NIB 加载,以模态方式使用presentModalViewController 消息。

该过程工作正常,但我注意到(使用分配工具)每次视图控制器以模态方式呈现(或通过导航控制器推送)时,内存一旦被解除就不会被回收。最终发生的情况是,如果用户多次激活模式视图控制器,最终应用程序将收到内存警告并最终崩溃。

我正在尝试找到一种方法来强制释放为模式视图控制器分配的内存。此时,我已经创建了父视图控制器拥有的视图控制器的单个实例,并为所有模式调用重新使用该视图控制器。

任何有关释放已解除的模态视图控制器的帮助将不胜感激。

谢谢你们!

I'm trying to present a custom view controller, with custom views loaded from detached NIBs, modally using the presentModalViewController message.

The process works fine but I noticed (using the allocations instruments) that every time the view controller is presented modally (or by a nav controller push) the memory is not being reclaimed once dismissed. What ends up happening is that if the user activates the modal view controller several times eventually the application will receive a memory warning and eventually crash.

I'm trying to find a way to force-release the memory allocated for the modal view controller. At this point, i've gone as far as to create a single instance of the view controller owned by the parent view controller and re-use the view controller for all modal invocations.

Any help with regards to releasing dismissed modal view controllers would be greatly appreciated.

Thanks guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぶ宁プ宁ぶ 2024-12-07 14:30:23

在调用 presentModalViewController:animated: 后,如果不再需要呈现的视图控制器,可以释放它。只要它存在,UIKit 本身就会保留它。

After you call presentModalViewController:animated:, you can release the presented view controller if you have no further need for it. UIKit will itself retain it as long as it is presented.

小草泠泠 2024-12-07 14:30:23

检查对象所有权。您的视图控制器负责呈现模式视图控制器,因此它保留其所有权。因此,您可以在实例化控制器后释放控制器并使用presentModalViewController:animated 呈现它。

Check out object ownership. Your view controller is responsible for presenting the modal view controller so it retains ownership of it. Thus, you can release the controller after you instantiate it and present it using presentModalViewController:animated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文