OnDeallocateX 2.1.0

OnDeallocateX 2.1.0

Siarhei Ladzeika 维护。



  • Siarhei Ladzeika

OnDeallocateX

用于跟踪 iOS 对象释放的辅助代码

安装

CocoaPods

添加到您的 Podfile

pod 'OnDeallocateX'

手动操作

克隆仓库,然后将 "Sources" 文件夹包含到您的项目中。

使用方法

要跟踪的对象的类应继承自 NSObject。

class TestObject: NSObject {
	deinit {
		print("deinit")
	}
}

let t = TestObject()
let k = t.onWillDeallocate {
	// NOTE: Please do not keep strong references to object inside this callback!!!
	print("will deallocate")
}

// Here object is deallocated, because no more references to it and you will see in console:
// ...
// will deallocate
// deinit
// ...


// Also you can delete observation by:
t.removeOnDeallocate(forKey: k)

注意: onWillDeallocate 将在释放之前调用,但实际释放可以在稍后执行(在对象有额外的强引用的情况下)。

授权

MIT. 请参阅 LICENSE

作者