Memory management/freeing with delegate methods
Memory management/freeing with delegate methods
- Subject: Memory management/freeing with delegate methods
- From: Paul Borokhov <email@hidden>
- Date: Sat, 28 Apr 2007 10:52:31 -0700
Hello,
While still trying to resolve that pesky NSURLConnection issue, I've come across this problem that I hope someone here can help me resolve.
Currently I have code like this:
-(void) getWallCount:(id)anObject {
if (anObject != nil) {
...
} else {
[MKAsyncRequest facebookUsersGetInfo:[NSArray arrayWithObject:[facebook uid]] fields:[NSArray arrayWithObject:@"wall_count"] facebookConnection:facebook delegate:self selector:@selector(parseWallCount:)];
}
}
The MKAsyncRequest then creates a downloader object and handles all of the NSURLConnection data retrieval and storage issues, etc. Its connectionDidFinishLoading: method is:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSXMLDocument *returnXML = [[NSXMLDocument alloc] initWithData:responseData options:nil error:nil];
if ([_delegate respondsToSelector:_selector]) {
[_delegate performSelector:_selector withObject:[returnXML autorelease]];
}
[self release];
}
Then, the final step is the callback method. It's very simple:
- (void) parseWallCount:(id)anObject {
[NSThread detachNewThreadSelector:@selector(getWallCount:) toTarget:self withObject:anObject];
}
My question, however, is how to do this correctly. The current code will sporadically cause crashes due to dangling pointer/premature release issues. Simply doing [_delegate performSelector:_selector withObject:returnXML] will cause huge memory leaks.
So, what's the proper way of doing this? Thanks!
Paul
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden