代码如下:- (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)
{
} // 去掉这行就不会崩溃
[pool release];
}- (void)_MainThreadShowResult
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // ...
// ...
// ... [pool release];
}
我看到很多资料上写的是工作线程函数里必须用
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool release];
于是我加了,可是加了以后。运行一次 submitAnswersAndGetResult 函数没问题,第二次运行 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)
{
} // 去掉这行就不会崩溃
[pool release];
}- (void)_MainThreadShowResult
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // ...
// ...
// ... [pool release];
}
我看到很多资料上写的是工作线程函数里必须用
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool release];
于是我加了,可是加了以后。运行一次 submitAnswersAndGetResult 函数没问题,第二次运行 submitAnswersAndGetResult 就崩溃。
不知道为什么,高手指点一下。
谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货