Created
December 4, 2017 04:04
-
-
Save SunXiaoShan/4c0ea0db6884ad1d0fa7a7d3bbdb43d1 to your computer and use it in GitHub Desktop.
LeakTest2
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 | |
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