When to release / save an object that is passed to the second thread?

I pass the object to the second thread using the following code:

 (void)login:(id)sender
{
  platformMsgs_LoginRequest *loginRequest = [[[platformMsgs_LoginRequest alloc] init] autorelease];
//more code...
 [NSThread detachNewThreadSelector:@selector(sendLoginRequest:) toTarget:self withObject:loginRequest];
//more code...
}

- (void)sendLoginRequest:(platformMsgs_LoginRequest *)loginRequest
 {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 [loginRequest retain];
 NetSuiteBinding *binding = [NetSuiteServiceSvc NetSuiteBinding];
 NetSuiteBindingResponse *response = [binding loginUsingParameters:loginRequest      applicationInfo:nil partnerInfo:nil];
 [self performSelectorOnMainThread:@selector(loginOperationCompleted:)   withObject:response waitUntilDone:NO];
 [loginRequest release];
 [pool drain];
 }

My question is, is autorelease the correct way to handle the release of this object ?. As soon as it is transferred to the second thread, I save it and release it when it is no longer needed.

However, is it possible for an abstract to free an object before the secondary stream can save it ?. Should I create an ivar for this? So that I can free the object in performSelectorOnMainThread ?. I no longer need the object after entering, so Ivar doesn't look the right way. What is the best way to handle this? Thanks.

-Oscar

+5
2

detachNewThreadSelector:toTarget:withObject: :

aTarget anArgument , .

, , detachNewThreadSelector. .

+5

.

detachNewThreadSelector: toTarget: withObject:

aTarget anArgument , . ( exit class), aTarget aSelector .

. , , , .

+1

All Articles