Re: NSOperationQueue for NSXMLParser object
Re: NSOperationQueue for NSXMLParser object
- Subject: Re: NSOperationQueue for NSXMLParser object
- From: Marcel Weiher <email@hidden>
- Date: Thu, 5 Nov 2009 22:16:26 -0800
Hi Chris,
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.
How large are the XML files? Does each contain multiple animation
steps or just one?
The XML is parsed at a given interval using an NSTimer. As
expected, sometimes when the XML is being parsed the animation stalls.
Do your stalls happen because of the parsing or because of the
downloading? The fact that you are using -initWithURL: suggests that
your stalls may be because of downloading, as -[NSXMLParser
initWithURL:] will download the entire XML file first and then start
parsing it.
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?).
Yes. There are two likely sources of performance issues: I/O and CPU
usage. Objective-XML solves both of these problems: it uses
overlapped/incremental parsing to get better responsiveness for
network loads and offers much higher parsing performance (roughly 10x
faster).
http://www.metaobject.com/Technology/
http://www.metaobject.com/downloads/Objective-C/Objective-XML-5.0.1.tgz
There's a blog post discussing the effects of incremental parsing on
(perceived) performance here:
http://www.metaobject.com/blog/2009/01/iphone-xml-performance.html
Summary: incremental parsing will typically get you much, much
better responsiveness if there is network I/O.
//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
}
...
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”.".
Since you are crashing on the 2nd firing of the timer, my guess is
that the problem is in code that you are not showing here.
Cheers,
Marcel
_______________________________________________
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