简体   繁体   English

视图控制器未释放内存的问题

[英]Issue with view controller not releasing memory

I'm working on an app where different view controllers get pushed and dismissed via dismissModalViewControllerAnimated. 我正在开发一个应用程序,其中不同的视图控制器通过dismissModalViewControllerAnimated推入和关闭。

I'm having some memory issues with the app just crashing after a while. 我的应用程序出现了一些内存问题,不久后崩溃了。 Looking at the Leaks instrument, I see that my overall allocations keeps going up and up. 查看泄漏工具,我发现我的总体分配一直在上升。 Even after the viewcontroller is dismissed, memory does not go down. 即使关闭了视图控制器,内存也不会减少。

Are there any obvious reasons for this? 有什么明显的原因吗? What is the simplest and easiest way to find out why my app is crashing? 找出导致我的应用崩溃的最简单,最简单的方法是什么? Thanks 谢谢

POSSIBLE SOLUTIONS 可能的解决方案

I went through some trial and error as well as googling and made a few changes: 我经历了一些试验和错误以及谷歌搜索,并进行了一些更改:

1) A delegate relationship may have been retaining the viewController, so I changed the object's delegate property to weak. 1)委托关系可能一直保留viewController,所以我将对象的委托属性更改为弱。

2) NSTimer's should be invalidated before dismissing viewController. 2)在关闭viewController之前,应使NSTimer无效。

3) UIView animations may interfere with dealloc being called? 3)UIView动画可能会干扰dealloc的调用? You can use [view.layer removeAllAnimations] to end them before popping your viewController. 您可以在弹出viewController之前使用[view.layer removeAllAnimations]结束它们。

If your memory is not go down after the dismissModalViewControllerAnimated .. it means you are creating the Global Object of the ViewController And after dismissing you are not setting the Object = nil ; 如果在dismissModalViewControllerAnimated ..之后内存没有减少,则表示您正在创建ViewControllerGlobal Object ,并且在dismissing后未设置Object = nil ;

If you set nil then your memory goes down automatically. 如果设置为nil,则内存会自动关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM