I have a set of objects, init'd and owned by a view controller. The view controller starts a fetchData method in each of these objects, which runs in a background thread and then, when it's done, returns the main thread and changes a property - self.dataFetchComplete, which the view controller is observing.
dispatch_async(dispatch_get_main_queue(), ^{
self.dataFetchComplete = YES;
});
If the view controller is deallocated before these objects are finished with this method, when it hits the self.dataFetchComplete = YES; line, it crashes.
How can i stop it from crashing when trying to change this property after being deallocated.
EDIT: More info, and clarity.
That block has a strong reference to self. The only way self could be deallocated is if you are over-releasing it elsewhere (as @Catfish_Man indicated).
if you have a crash, post the backtrace of the crash
if you have an over-release crash, use Instruments to track all retain/release events on the object.
run the analyzer and fix any problems it indicates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With