Skip to content

Instantly share code, notes, and snippets.

@froggomad
Last active May 29, 2021 17:35
Show Gist options
  • Save froggomad/be87f5e7f1f83a3091775ca8e5281452 to your computer and use it in GitHub Desktop.
Save froggomad/be87f5e7f1f83a3091775ca8e5281452 to your computer and use it in GitHub Desktop.
Test for retain cycles, reusably
private func assertNoMemoryLeak(_ instance: AnyObject, file: StaticString = #filePath, line: UInt = #line) {
addTeardownBlock { [weak instance] in
XCTAssertNil(instance, "Instance should have been deallocated. Potential retain cycle.", file: file, line: line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment