Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created December 4, 2017 04:04
Show Gist options
  • Save SunXiaoShan/4c0ea0db6884ad1d0fa7a7d3bbdb43d1 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/4c0ea0db6884ad1d0fa7a7d3bbdb43d1 to your computer and use it in GitHub Desktop.
LeakTest2
// 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
var obj1 = LeakObject("Obj 1")
weak var obj2 = LeakObject("Obj 2")
obj1.node = obj2
obj2?.node = obj1
obj1 = LeakObject("")
obj2 = LeakObject("")
// output
// Init object - Obj 1
// Init object - Obj 2
// Dealloc object - Obj 2
// Dealloc object - Obj 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment