Skip to content

Instantly share code, notes, and snippets.

@quentinfasquel
Last active February 10, 2019 20:54
Show Gist options
  • Save quentinfasquel/ccc710959bdd014faaebd916ffdf43ce to your computer and use it in GitHub Desktop.
Save quentinfasquel/ccc710959bdd014faaebd916ffdf43ce to your computer and use it in GitHub Desktop.
// 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