为什么 ARC 在 popViewController 之后不释放内存 [英] Why ARC is not deallocating memory after popViewController

查看:21
本文介绍了为什么 ARC 在 popViewController 之后不释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 UINavigationController 中推送和弹出 ViewController.

我正在跟踪我的应用程序的内存消耗.在推送新的 viewController 时,内存消耗逐渐增加,但是当我使用 [self.navigationController popViewControllerAnimated:NO]; 弹出同一个 ViewController 时,内存消耗并没有减少而是保持不变.p>

用户可以多次推送和弹出特定的viewController,这会导致应用程序在RAM中的高内存消耗.

我应该如何优化我的内存消耗?

解决方案

当您关闭视图控制器(或弹出它)时,如果您没有对它进行任何强指针,它将被释放(该控制器由导航控制器或呈现视图控制器,因此您在创建并推送或呈现它时通常不需要指向它的指针).

如果没有其他强指针会被释放

I'm pushing and popping ViewControllers in UINavigationController.

I'm tracking the memory consumption of my app. While pushing the new viewController the memory consumption is increasing gradually, but when I'm popping the same ViewController using [self.navigationController popViewControllerAnimated:NO]; the memory consumption does not decrease but the constant.

That particular viewController can be pushed and popped by user many times which can lead the high memory consumption of app in RAM.

What should I do to optimise my memory consumption?

解决方案

When you dismiss a view controller (or pop it), it will be deallocated if you didn't make any strong pointers to it (that controller is retained by the navigation controller, or the presenting view controller, so you usually don't need to have a pointer to it when you create it and push or present it).

It will be be released if there are no other strong pointers to it

这篇关于为什么 ARC 在 popViewController 之后不释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆