【问题标题】:swift pushViewController memoryswift pushViewController 内存
【发布时间】:2014-07-28 13:03:53
【问题描述】:

我正在使用以下代码将一个新的视图控制器推送到堆栈中,ViewController 是用笔尖初始化的,并且只包含一个 webview,该类是完全空的。

    var profileVC = GenericWebViewController()
    profileVC.initWithURL(url)
    navigationController.pushViewController(profileVC, animated:true)

当视图被按下时,内存使用率上升,然而,当按下返回按钮时,内存水平并没有下降。

我应该怎么做才能让profileVC 被垃圾回收?

【问题讨论】:

    标签: ios memory-leaks swift


    【解决方案1】:

    什么都没有;)

    自动引用计数会自动为您处理此问题

    http://clang.llvm.org/docs/AutomaticReferenceCounting.html

    编辑:内存可能不会因为其他原因而下降。检查您没有任何strong reference cycles。要 100% 确定您的 GenericWebViewController 正在从内存中清除,请覆盖其 dealloc 方法并确保它正在被调用。

    还可以查看leaks instrument

    【讨论】:

    • 那为什么内存使用量没有下降呢?
    • @gibo 我添加了更多信息以及一些可能发生的情况。当然,Web 视图可能会在您的控制范围内分配大量一次性创建内存
    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 2011-02-01
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多