Skip to content

Instantly share code, notes, and snippets.

@hmlongco
Created January 9, 2023 22:57
Show Gist options
  • Save hmlongco/d1c43270084d8043555514aa375cc6d3 to your computer and use it in GitHub Desktop.
Save hmlongco/d1c43270084d8043555514aa375cc6d3 to your computer and use it in GitHub Desktop.
DeinitTracking
class DeinitTracker {}
class Test {
init() {}
#if DEBUG
lazy var deinitTracker: DeinitTracker? = DeinitTracker()
#endif
}
final class MyTests: XCTestCase {
func testDeinitTracking() throws {
var object: Test? = Test()
var reference: Test? = object
weak var tracker = object?.deinitTracker
object = nil
XCTAssertNil(object)
XCTAssertNotNil(reference)
XCTAssertNotNil(tracker)
reference = nil
XCTAssertNil(object)
XCTAssertNil(reference)
XCTAssertNil(tracker)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment