Reputation: 9157
I have a class that handles all the Network Access on the iPhone. And I use it in the following way:
-(void) randomFunction:
{
// Assign params etc. <br />
TTNetworkAccessLib *nLib = [[TTNetworkAccessLib alloc] initWithParams:..];
[nLib createAndStartRequest];
// Can't release here since the request is async and is still running.
}
-(void) requestSucceded:(NSData *) data
{
// Can pass a reference to the request object and release here, but doesn't seem right?
}
-(void) requestFailed:(int) responseCode
{
// Can pass a reference to the request object and release here, but doesn't seem right?
}
Upvotes: 0
Views: 51
Reputation: 39905
When I create an object to do something asynchronously, I usually have it retain itself when starting the procedure and release itself after finishing and completing any callbacks. This way, the code creating it can release it if it doesn't need it later, and I know it will not be deallocated until the process has completed.
Upvotes: 2
Reputation: 1241
With a delegate like that I would recommend to use the autorelease TNetworkAccessLib *nLib = [[[TTNetworkAccessLib alloc] initWithParams:..] autorelease];
Upvotes: 0