使用 NSThread 加载地图时,应用程序在交替运行时崩溃
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该花时间阅读 线程编程参考,关于线程管理章节。
I think you should spend time to read thread programming reference, about the chapter of Thread Management.