Skip to content

Instantly share code, notes, and snippets.

@erkekin
Created June 15, 2022 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erkekin/0f44eefb62f62e9f79b8f544ca2dd46e to your computer and use it in GitHub Desktop.
Save erkekin/0f44eefb62f62e9f79b8f544ca2dd46e to your computer and use it in GitHub Desktop.
Test strong reference cycles within unit tests
public func AssertNoStrongReferenceCycle<T: AnyObject>(
file: StaticString = #file,
line: UInt = #line,
act: () throws -> T
) rethrows {
weak var system: T?
try autoreleasepool {
system = try act()
}
XCTAssertNil(system, "You've got a reference cycle in \(T.self).", file: file, line: line)
}
@erkekin
Copy link
Author

erkekin commented Jun 15, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment