views:

64

answers:

1

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;
+1  A: 

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".

Ben Gottlieb
check my updated code. am i creating the auto-release pool correctly?
Sheehan Alam
@Sheehan, you must put NSAutoreleasePool inside your performReachabilityCheck method (the one, that runs in background)
Vladimir