ASIHTTPRequest popViewControllerAnimated: => delegate EXEC_BAD_ACCESS <p>I set the view controller to be the delegate of a local variable <code>ASIHTTPFormDataRequest request</code>.</p> <p>But, tapping "Back" before the request has finished, pops and deallocates the view controller. So, when the request completes and sends the message <code>-requestDidFinish:</code> to the now nonexistent delegate, the app crashes with an <code>EXEC_BAD_ACECESS</code> exception.</p> <p>How do I fix this crash?</p> <ol> <li><p>One way I could think of solving this is to set the delegate to nil immediately after the navigation controller pops it. But, if that's the solution, how do I do that? (ARC's <code>weak</code> references would be sweet right now.)</p></li> <li><p>Another way I can think of is to make <code>request</code> an instance variable of the view controller and call <code>[request clearDelegatesAndCancel]; [request release];</code> in the view controller's <code>dealloc</code> method. This approach is outlined in <a href="http://allseeing-i.com/ASIHTTPRequest/How-to-use" rel="nofollow">ASIHTTPRequest Example Code</a>, but I've been advised it's best to make requests local variables instead of instance variables. And, this particular view controller is a settings table view controller and has 13 switches. For automatic saving to the server, each switch creates &amp; sends a new request each time it's toggled. If I made ivars, I'd have to make 13. That's a lot of code!</p></li> </ol> <p>Thoughts? Ideas?</p>