iphone – Will this code leak memory? – Education Career Blog

I am calling in applicationDidFinishLaunching:

self performSelectorInBackground:@selector(performReachabilityCheck) withObject:nil;

Here is the performReachabilityCheck

-(void)performReachabilityCheck{
    internetReach = Reachability reachabilityForInternetConnection retain;
    internetReach startNotifer;
    self updateInterfaceWithReachability: internetReach;
}

Do I need to create an auto-release pool? If so, how can I do that in this context?

UPDATE:
Is this the correct way to implement the auto-release pool?

NSAutoreleasePool * pool = NSAutoreleasePool alloc init;
    self performSelectorInBackground:@selector(performReachabilityCheck) withObject:nil;
    pool release; pool = nil;

,

Yes, anytime you perform a selector on a background thread, you need to wrap it in an AutoreleasePool. The classes you’re using may create autoreleased objects. If you run this while connected to the debugger, you should see a lot of messages about “No autorelease pool in place, just leaking”.

Leave a Comment