waheeda
waheeda

Reputation: 1097

ASINetworkQueue:trying to perform selector on deallocated delegate

I am using the sample code from https://gist.github.com/150447

when the viewcontroller unloads, im setting the networkqueue to nil, and also calling the reset method.

[[self networkQueue1] reset];
[self setNetworkQueue1:nil];

but still i get exception as soon as i go back to previous view controller.

* -[myViewController performSelector:withObject:]: message sent to deallocated instance 0xc1d1bb0

Please suggest whats going wrong.

Thanks,

Upvotes: 2

Views: 816

Answers (2)

JosephH
JosephH

Reputation: 37495

You need to nil any delegates in the dealloc() method or earlier. Depending on exactly which delegates etc you're setting, something like this should do it:

for (ASIHTTPRequest *req in [queue operations])
{
    [req cancel];
    [req setDelegate:nil];
}
[queue setDelegate:nil];

Basically, you need to make sure the delegate is removed any current request before the delegate is destroyed - this will make sure that a deallocated delegate will never get called.

Upvotes: 3

Rayfleck
Rayfleck

Reputation: 12106

Please see this post NSURLConnection gives EXC BAD ACCESS when tap on other tab while data loading

Basically, an object still has a reference to your view controller (probably so it can do a callback to it), and when you go back to the previous VC, the current VC is being deallocated (as it should.) You need to find that object, and nill out it's reference to your VC (probably called "delegate" or "callback"). Hope that helps.

Upvotes: 0

Related Questions