Created
December 4, 2017 03:59
-
-
Save SunXiaoShan/5ee420663b1ee46aebcb4ebe2e5fe529 to your computer and use it in GitHub Desktop.
LeakTest 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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