DeallocationChecker

无需打开 Instruments 即可了解有关内存泄漏的视图控制器。

Build Status

用法

首先,通过调用启用库(例如,从您的应用程序委托中调用)

#if DEBUG
    DeallocationChecker.shared.setup(with: .alert) // There are other options than .alert too!
#endif

然后,在您的视图控制器中,viewDidDisappear(_:) override,调用

override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)

    DeallocationChecker.shared.checkDeallocation(of: self)
}

如果一个视图控制器在完全消失后没有被释放,您将会看到一个有用的警告

Leaked view controller demo

此时,我们可以简单地打开 内存图调试器 来调查循环的原因。

安装

CocoaPods

将这行代码 pod "DeallocationChecker" 添加到您的 Podfile

Carthage

将这行代码 github "fastred/DeallocationChecker" 添加到您的 Cartfile

作者

项目由 Arek Holko 创建 (@arekholko 在 Twitter 上).