我的应用程序存在内存问题,
我有一个基于导航的应用程序,如果我推送、弹出和推送我的所有 Controller ,该应用程序将由于内存过载而关闭。
我认为这就是我们所说的保留周期:
我有一个自定义导航 Controller :MyNavController
,这个Controller是我的根 Controller ,并且推送主UIViewController
: MyMainController
,当应用程序启动应用程序使用大约 130 MB 内存时,当我推送一个新 Controller 时:内存上升到 160,然后我弹出这个 Controller :内存仍然是 160(确切地说是 159)然后我推送另一个 View Controller :内存高达 190 MB ...内存永远不会下降。
UIViewController
并将我的xib中的 View 设置为我的一个未发布的 Controller ,这样它可能比清晰更重,所以这个 Controller 没有代码行,只是一个没有自定义代码的.h和.m,当我插入这个 Controller 时内存上升,当我弹出它时,内存不会下降!我真的不明白我要寻找什么,我必须在我的MainViewController
上寻找吗? ?还是在 Controller 中我插入堆栈? 我只需使用以下命令加载我的 Controller :
GeoControllerViewController *aGeoController = [[GeoControllerViewController alloc] initWithNibName:@"GeoControllerViewController" bundle:nil];
aGeoController.dictionnaryModele = _dicCours;
[self.navigationController pushViewController:aGeoController animated:YES];
提前致谢。
最佳答案
你问:
Can you confirm me that is a retain cycle?
不,可能是泄漏。可能是缓存。可能是一个保留周期。我们无法判断您与我们分享的内容。
If i'm not wrong when i pop a view controller the memory should decrease of the view controller memory size?
一般来说,当你弹出时它应该会减少,但如果对任何东西使用缓存,或者如果填充共享模型或你有什么,它可能不会完全恢复到初始推送之前的内存水平。话虽如此,如果有缓存在起作用,如果您多次推送和弹出,您在分配中看到的总“事件字节”应该在您推送和弹出几次后恢复到一致的水平。
I always use strong into my properties (button, view, customView, customObject...) but when i set a breakpoint into my second level controller into the dealloc method i know that it is called, so the controller should be released?
如果
dealloc
该 Controller 被调用,它告诉您这不涉及任何保留周期,并且与 Controller 关联的内存将由系统恢复。从理论上讲,它的任何强大属性也应该被释放。顺便说一句,通常是您的
IBOutlet
引用(即由 NIB/ Storyboard创建的那些东西)应该是 weak
在 ARC 项目中。一些具体的建议:
参见 WWDC 2012 视频 iOS App Performance: Memory有关如何执行此操作的一些演示。
关于iphone - 假人的 ARC 保留周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19420369/