The question was discussed here and here , but I wonder if there is a more reliable way to solve this, whether you have delegates or not - when the function is called after a delay. At a certain point in the program, when you click the button, an object is created - CCLayer. This layer creates several objects, some of them in callbacks. This created object layer has a back button that destroys it. I ran into a problem when calling calls, etc. Run AFTER this object is destroyed, and try to access objects that no longer exist - where "the message sent to the freed instance 0x258ba480" gives me this good news. How to avoid this?
1) Is there a way to kill callbacks (because I obviously donβt need them anymore) 2) should / I can check for the presence of these possibly nonexistent objects in the callbacks themselves 3) something else?
(My callback is the code for checking the Internet connection that I copied from this illustrious website - can it live long and flourish using Reachability, and I could solve the problem by simply moving it to the main screen and installing flag on child view but i don't want to.)
- (void)testInternetConnection
{
internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];
internetReachableFoo.reachableBlock = ^(Reachability*reach)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Yayyy, we have the interwebs!");
});
};
internetReachableFoo.unreachableBlock = ^(Reachability*reach)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Someone broke the internet :(");
noNetMessageLabel.visible=true;
noNetFlag=true;
});
};
[internetReachableFoo startNotifier];
}
source
share