Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory management/freeing with delegate methods



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.