FROM : Paul Borokhov
DATE : Sat Apr 28 19:52:31 2007
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
DATE : Sat Apr 28 19:52:31 2007
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
| Related mails | Author | Date |
|---|---|---|
| Paul Borokhov | Apr 28, 19:52 | |
| Scott Stevenson | Apr 28, 20:19 | |
| Paul Borokhov | Apr 28, 20:49 | |
| Buddy Kurz | Apr 28, 21:34 | |
| Scott Stevenson | Apr 28, 22:32 | |
| Paul Borokhov | Apr 28, 23:01 | |
| Shawn Erickson | Apr 29, 00:11 | |
| Matt Neuburg | Apr 30, 01:52 |






Cocoa mail archive

