NSOperationQueue for NSXMLParser object
NSOperationQueue for NSXMLParser object
- Subject: NSOperationQueue for NSXMLParser object
- From: Chris Purcell <email@hidden>
- Date: Thu, 05 Nov 2009 18:12:31 -0800
Let me start with what I'm trying to accomplish. I have an app that
is constantly running an animation, which's attributes are determined
after downloading and parsing some XML. The XML is parsed at a given
interval using an NSTimer. As expected, sometimes when the XML is
being parsed the animation stalls. I've determined that I'll need to
do the parsing on a separate thread from the main thread (Unless there
is a better solution?).
I'm running into some problems using NSOperation with a NSTimer. Here
are some portions of the code:
//From the App delegate
//create a timer to parse the XML
self.timer = [NSTimer scheduledTimerWithTimeInterval: 2
target: self
selector: @selector(parseXML:)
userInfo: nil
repeats: YES];
//Parse the XML
- (void) parseXML:(NSTimer *)timer {
XMLParser *parser = [[XMLParser alloc] initWithURL:@"Location of the
XML" delegate:self];
[queue addOperation:parser];
[parser release]; //this is where my problem is
}
XMLParser is a subclass of NSOperation, here is some of that class.
- (void)main {
[self startParsing]; //this method starts the parsing
}
When the parsing is complete, I use this code to send the result
back to the delegate object:
//sends the result back to the delegate
if ( [delegate respondsToSelector:@selector(status:)] ) {
[delegate status:self.result];
}
This code works, as long as I don't release the parser object after
this:
[queue addOperation:parser];
[parser release];
However, if I don't release the Parser object, the app leaks like
crazy, since it's creating new Parser objects on each fire of the
timer. When I release the parser, the second fire the app terminates:
"Program received signal: “EXC_BAD_ACCESS”.".
Thank you for any advice!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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