Last active
February 10, 2019 20:54
-
-
Save quentinfasquel/ccc710959bdd014faaebd916ffdf43ce to your computer and use it in GitHub Desktop.
This file contains 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
// CatchingException.swift | |
{ | |
let failingObject = MyFailingObject() | |
if let exception = objc_tryCatch({ failingObject.throwException() }) { | |
// Here we caught the exception, but we actually leaked failingObject | |
} | |
// Let's check that it's actually leaking | |
weak var weakFailingObject: FailingObject? = failingObject | |
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { | |
if weakFailingObject != nil { | |
// If weakFailingObject is not nil, this means failingObject leaked | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment