I dev for iphone, My code is:
----------------------------------------------------------------------------------------------------
call submitAnswersAndGetResult for the first time, it works well, but the second time, it crashed.
I read the XCode document, and find the following descriptions:
----------------------------------------------------------------------------------------------------
For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits. Garbage-collected applications do not need to create an autorelease pool.
But, how I knew that my program is a non garbage-collected applications or a Garbage-collected applications?
Do I need to create an autorelease pool?
Thank you very much!
----------------------------------------------------------------------------------------------------
Code:
- (void)submitAnswersAndGetResult
{
[ NSThread detachNewThreadSelector:@selector(_ThreadSubmitAnswersAndGetResult) toTarget:self withObject:nil ];
}
- (void)_ThreadSubmitAnswersAndGetResult
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@try
{
// ...
// ...
[self performSelectorOnMainThread:@selector(_MainThreadShowResult) withObject:nil waitUntilDone:YES];
}
@catch (NSException * e)
{
}
[COLOR="Red"]// If removes the following line, program will not crash[/COLOR]
[pool release];
}
- (void)_MainThreadShowResult
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// ...
// ...
// ...
[pool release];
}
call submitAnswersAndGetResult for the first time, it works well, but the second time, it crashed.
I read the XCode document, and find the following descriptions:
----------------------------------------------------------------------------------------------------
For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits. Garbage-collected applications do not need to create an autorelease pool.
But, how I knew that my program is a non garbage-collected applications or a Garbage-collected applications?
Do I need to create an autorelease pool?
Thank you very much!
Last edited by a moderator: