iphone - 假人的 ARC 保留周期

标签 iphone ios memory-management automatic-ref-counting block

我的应用程序存在内存问题,

我有一个基于导航的应用程序,如果我推送、弹出和推送我的所有 Controller ,该应用程序将由于内存过载而关闭。

我认为这就是我们所说的保留周期:

我有一个自定义导航 Controller :MyNavController ,这个Controller是我的根 Controller ,并且推送主UIViewController : MyMainController ,当应用程序启动应用程序使用大约 130 MB 内存时,当我推送一个新 Controller 时:内存上升到 160,然后我弹出这个 Controller :内存仍然是 160(确切地说是 159)然后我推送另一个 View Controller :内存高达 190 MB ...内存永远不会下降。

  • 你能确认我这是一个保留周期吗?
  • 如果我在弹出 View Controller 时没有错,那么内存应该减少 View Controller 内存大小吗?
  • 我总是在我的属性(按钮、 View 、customView、customObject ...)中使用强,但是当我在我的二级 Controller 中设置断点到 dealloc 方法时,我知道它被调用了,所以应该释放 Controller ?
  • 我尝试了一些东西:我做了一个空的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 项目中。

    一些具体的建议:
  • 通过静态分析器(Xcode“产品”菜单上的“分析”)运行您的代码,并确保那里的警告为零。如果有,请先修复它们。
  • 通过 Instruments 中的 Leaks 工具运行您的代码,看看它是否报告了什么。如果是这样,那将告诉您如何进行。
  • 如果仍然找不到问题,请使用 Instruments 中的 Allocations 工具运行该工具,在进入下一个场景之前标记一个 heapshot/generation,进入下一个场景,返回并标记另一个 heapshot/generation。然后,您可以及时分析在这两个时刻之间分配和未释放的内容,这将告诉您接下来要查找的内容。
    参见 WWDC 2012 视频 iOS App Performance: Memory有关如何执行此操作的一些演示。
  • 关于iphone - 假人的 ARC 保留周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19420369/

    相关文章:

    iphone - 在 UIButton 上使用两个不同的控制事件

    iphone - IOS 5 - 从另一个 ViewController 调用一个 ViewController

    ios - 是否可以在 UIImage 之外使用 SF 符号?

    ios - 带有数组字符串的子字符串 - Swift

    iphone - AFNetworking (AFJSONRequestOperation) 转换为 AFHTTPClient

    ios - 表格 View 单元格分隔线从远处看不到

    c++ - C++ 程序的内存使用量增长,(在 Debian 的 "top"中显示),直到它崩溃

    java - Android——多个 Activity 、保持 Activity 状态并保存状态?

    ios - 将 OpenGL 帧缓冲区绘制到 UIImage 时内存泄漏

    iphone - Xcode 错误-线程 1 : signal SIGABRT