Mugunth
Mugunth

Reputation: 14509

Multi-threading with iPhone SDK

I'm using a separate NSAutoReleasePool for my thread

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
[self bulkyFunction]; // time consuming op
[self performSelectorOnMainThread: @selector(doneAll) withObject:nil waitUntilDone:NO];
[pool release];

and I call a function (bulkyFunction) that allocates two strings.

    currentTitle = [[NSMutableString alloc]init];
    currentSummary = [[NSMutableString alloc]init];

I release them after using.

This thread is called periodically. But when it's called the second time, accessing currentTitle crashes.

Is it because my [pool release] statement releases currentTitle which has already been released by [currentTitle release] statement? Because, if the [currentTitle release] is commented out, there is no problem. But i'm worried about memory leaks.

Please advice.

Upvotes: 0

Views: 2866

Answers (1)

Steven Canfield
Steven Canfield

Reputation: 7332

[pool release] will not release currentTitle unless you call [currentTitle autorelease] somewhere. I think it would be helpful if you posted the entirety of bulkyFunction.

Upvotes: 4

Related Questions