Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created December 4, 2017 03:59
Show Gist options
  • Save SunXiaoShan/5ee420663b1ee46aebcb4ebe2e5fe529 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/5ee420663b1ee46aebcb4ebe2e5fe529 to your computer and use it in GitHub Desktop.
LeakTest 1
// define object
class LeakObject: NSObject {
var node:LeakObject?
var name:String = ""
init(_ name:String) {
super.init()
self.name = name
self.name == "" ? () : print("Init object - \(self.name)")
}
deinit {
self.name == "" ? () : print("Dealloc object - \(self.name)")
}
}
// Demo
weak var obj1 = LeakObject("Obj 1")
var obj2 = LeakObject("Obj 2")
obj1?.node = obj2
obj2.node = obj1
obj1 = LeakObject("")
obj2 = LeakObject("")
// output
// Init object - Obj 1
// Dealloc object - Obj 1
// Init object - Obj 2
// Dealloc object - Obj 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment