dispatch_after is persisting view controller in memory <p>I have this code, which runs a block of code after a delay.</p> <pre><code>public func delay(delay:Double, closure:()-&gt;()) { dispatch_after( dispatch_time( DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)) ), dispatch_get_main_queue(), closure) } </code></pre> <p>The problem is that the view controller using the delay function persists even after dismissal. With the code removed, it becomes nil, as it should.</p> <p>I need to know how to have a delay function, like this, but which wouldn't persist the object it was called from, and instead would just not call the block, in the event that it's otherwise no longer existent.</p> <p>This is in Swift, but replies in Objective-C are entirely appreciated.</p>