• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Memory management/freeing with delegate methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Memory management/freeing with delegate methods
      • From: Buddy Kurz <email@hidden>
    • Re: Memory management/freeing with delegate methods
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: Rotating an NSView before printing
  • Next by Date: Re: Memory management/freeing with delegate methods
  • Previous by thread: Nesting NSImageView inside NSScrollView
  • Next by thread: Re: Memory management/freeing with delegate methods
  • Index(es):
    • Date
    • Thread