开发者

performSelectorInBackground error debugging

I'm newbie on iPhone threading programming and I'm a bit loss.

I have a function wich parses XML and generates an array of objects that works fine on main background, but I need to execute in background, so I call performSelectorInBackground, but debugger throws an EXC_BAD_ACCESS, I tried to debug it but it chrashes in different points, and when I run Instruments for get memory leaks, app doesn't crash.

Any suggestion for debug my app?

Thanks in advance.


I've changed it but errors continues. EXC_BAD_ACCESS is throwed in NSXMLParserDelegate, I trace it with NSLog and different numbers for each line and each execution it crashes in a different line...

I'm completly lost


What do you mean with shared resources? XML files for example?

That's the code running in background.

NSAutore开发者_开发知识库leasePool *arPool = [[NSAutoreleasePool alloc] init];

    //Cargamos las noticias desde el servidor.
    NSString *metadataPath = [[NSBundle mainBundle] pathForResource:@"classes" ofType:@"xml"];
    RESTXML *restXML = [[RESTXML alloc] initWithXMLMetadata:metadataPath];  

    NSString *testXMLPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"xml"];
    NSData *xmlData = [NSData dataWithContentsOfFile:testXMLPath];
    NSMutableArray *latestNews = [(NSMutableArray*)[restXML REST2Object:@"doc" andXML:xmlData] retain];

    [self performSelectorOnMainThread:@selector(uploadTableData) withObject:nil waitUntilDone:NO];

    [arPool release];

Could you point me for some documentation about mutexes in iPhone?

Thanks a lot for your time


If you're using multiple threads, make sure you've added mutexes (using @synchronize keyword) for all places where you're accessing resources shared among threads.


You could try to change that line:

[self performSelectorOnMainThread:@selector(uploadTableData) withObject:nil waitUntilDone:NO];

with

[self performSelectorOnMainThread:@selector(uploadTableData) withObject:nil waitUntilDone:YES];

if your table view accesses data created in your thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜