views:

27

answers:

2

Hi Everyone:

In my iPhone application, I have an instance of NSXMLParser that is set to a custom delegate to read the XML. This is then moved into its own thread so it can update the data in the background. However, ever since I have done this, it has been giving me a lot of _NSAutoreleaseNoPool warnings in the console. I have tried to add a NSAutoreleasePool to each of my delegate classes, however, this hasn't seemed to solve the problem. I have included my method of creating the NSXMLParser in case that is at fault.

NSURL *url = [[NSURL alloc] initWithString:@"http://www.mywebsite.com/xmlsource.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

CustomXMLParser *parser = [[CustomXMLParser alloc] init];

parser.managedObjectContext = self.managedObjectContext;

parser = [parser initXMLParser];

[xmlParser setDelegate:parser];

[NSThread detachNewThreadSelector:@selector(parse) toTarget:xmlParser withObject:nil];

If anyone has any ideas to get rid of this problem, I would really appreciate it.

Thanks.

+1  A: 

In objective-c each thread needs its own NSAutorelease pool to handle autoreleased objects. So in your parse method you need to create (and release) NSAutoreleasePool object:

- (void)parse{
   NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
   ...
   // your method implementation
   ...
   [pool release];
}
Vladimir
It's best to wrap everything in a @try { ... } @finally { [pool release]; } too, in case you get some exception which trashes the thread. Course an exception will likely abort your app, but still.
Mike Weller
Thanks Mike, good point
Vladimir
Thanks for your reply Vladimir! However, I am calling parse on the NSXMLParser - do I need to override this somewhere?
PF1
A: 

1 [email protected] Test Mail 12-12-2010 1 images.jpg

Why pasing stops at from tag?? plz help me..

Sam