使用 NSThread 加载地图时,应用程序在交替运行时崩溃

发布于 2024-10-06 02:20:44 字数 560 浏览 0 评论 0原文

我正在使用 NSThread 与主线程同时执行一些工作。我已在 iPhone 3G 上部署了该应用程序 该应用程序在第一次运行时按预期工作。

但是,当我关闭该应用程序并再次运行它时,它立即崩溃。下次我运行该应用程序时,它又可以正常工作了。这不断重复。

我不知道为什么应用程序的早期运行会对下一次运行产生影响。 请帮忙!

这是我的代码:

NSThread *th=[[NSThread alloc]initWithTarget:self selector:@selector(loadMap) object:nil];
[th start]; 

-(void) loadMap{

    NSAutoreleasePool * pool=[[NSAutoreleasePool alloc]init];

    //code to load MKMapView

    [pool release];

}

提前致谢

如果我在两次运行之间打开另一个地图应用程序,应用程序不会崩溃! 如果我删除线程并串行加载地图,应用程序也可以正常工作

I am using NSThread to do some work concurrently with main thread. I've deployed the application on iPhone 3G
The application is working as expected in first run.

But, when I close the app and run it again, it crashes immediatly. The next time I run the app, it works fine again. this keeps on repeating.

I have no idea why earlier run of the app has an effect on the next run.
Please help!

Here is my code:

NSThread *th=[[NSThread alloc]initWithTarget:self selector:@selector(loadMap) object:nil];
[th start]; 

-(void) loadMap{

    NSAutoreleasePool * pool=[[NSAutoreleasePool alloc]init];

    //code to load MKMapView

    [pool release];

}

Thanks in advance

App won't crash if I open another map application in between two runs!
Also App works very fine if I remove the thread and load the map serially

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦年海沫深 2024-10-13 02:20:44

我认为你应该花时间阅读 线程编程参考,关于线程管理章节。

I think you should spend time to read thread programming reference, about the chapter of Thread Management.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文