IOS 5 消息通过 alloc 命令发送到已解除分配的实例
我在使用 ARC 的 Ios 5 应用程序上出现以下错误:
*** -[ViewDettaglio respondsToSelector:]: message sent to deallocated instance 0x12193300
在控制台上编写命令:
info malloc-history 0x12193300
并且得到以下堆栈跟踪:
Alloc: Block address: 0x12193300 length: 192 Stack - pthread: 0xa08a3540 number of frames: 31 0: 0x96bdab03 in malloc_zone_calloc 1: 0x96bdaa5a in calloc 2: 0x16f8c93 in class_createInstance 3: 0x170388b in _objc_rootAllocWithZone 4: 0x21af661 in +[NSObject allocWithZone:] 5: 0x17038b9 in _objc_rootAlloc 6: 0x2c4c8 in -[ViewElenco CaricaViewDettaglio:] at /Users/.../ViewElenco.m:186 7: 0x2e550 in -[ViewElenco mapView:annotationView:calloutAccessoryControlTapped:] at /Users/.../ViewElenco.m:337 8: 0x3fa99c 9: 0x405faa in MKLongHash 10: 0x21aeec9 in -[NSObject performSelector:withObject:withObject:] 11: 0x60d5c2 in -[UIApplication sendAction:to:from:forEvent:] 12: 0x60d55a in -[UIApplication sendAction:toTarget:fromSender:forEvent:] 13: 0x6b2b76 in -[UIControl sendAction:to:forEvent:] 14: 0x6b303f in -[UIControl(Internal) _sendActionsForEvents:withEvent:] 15: 0x6b22fe in -[UIControl touchesEnded:withEvent:] 16: 0x632a30 in -[UIWindow _sendTouchesForEvent:] 17: 0x632c56 in -[UIWindow sendEvent:] 18: 0x619384 in -[UIApplication sendEvent:] 19: 0x60caa9 in _UIApplicationHandleEvent 20: 0x1a95fa9 in PurpleEventCallback 21: 0x21811c5 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 22: 0x20e6022 in __CFRunLoopDoSource1 23: 0x20e490a in __CFRunLoopRun 24: 0x20e3db4 in CFRunLoopRunSpecific 25: 0x20e3ccb in CFRunLoopRunInMode 26: 0x1a94879 in GSEventRunModal 27: 0x1a9493e in GSEventRun 28: 0x60aa9b in UIApplicationMain 29: 0x20bb in main at /Users/.../main.m:14 30: 0x2065 in start
ViewElenco.m 第 186 行的代码如下:
ViewDettaglio *viewq=[[ViewDettaglio alloc] initWithNibName:@"ViewDettaglio" bundle:nil];
这是怎么发生的? 我正在使用 UINavigationController 从 ViewElenco 和 ViewDettaglio 进行导航。
编辑
以下代码中是否有可能:
ViewDettaglio* viewDettaglio=[[ViewDettaglio alloc] initWithNibName:@"ViewDettaglio" bundle:nil]; viewDettaglio.idObject=idObj; [self.navigationController pushViewController:viewDettaglio animated:YES];
alloc返回一个已释放的对象?
I have the following error on a Ios 5 application using ARC:
*** -[ViewDettaglio respondsToSelector:]: message sent to deallocated instance 0x12193300
on console i write command:
info malloc-history 0x12193300
and i get the following stack-trace:
Alloc: Block address: 0x12193300 length: 192 Stack - pthread: 0xa08a3540 number of frames: 31 0: 0x96bdab03 in malloc_zone_calloc 1: 0x96bdaa5a in calloc 2: 0x16f8c93 in class_createInstance 3: 0x170388b in _objc_rootAllocWithZone 4: 0x21af661 in +[NSObject allocWithZone:] 5: 0x17038b9 in _objc_rootAlloc 6: 0x2c4c8 in -[ViewElenco CaricaViewDettaglio:] at /Users/.../ViewElenco.m:186 7: 0x2e550 in -[ViewElenco mapView:annotationView:calloutAccessoryControlTapped:] at /Users/.../ViewElenco.m:337 8: 0x3fa99c 9: 0x405faa in MKLongHash 10: 0x21aeec9 in -[NSObject performSelector:withObject:withObject:] 11: 0x60d5c2 in -[UIApplication sendAction:to:from:forEvent:] 12: 0x60d55a in -[UIApplication sendAction:toTarget:fromSender:forEvent:] 13: 0x6b2b76 in -[UIControl sendAction:to:forEvent:] 14: 0x6b303f in -[UIControl(Internal) _sendActionsForEvents:withEvent:] 15: 0x6b22fe in -[UIControl touchesEnded:withEvent:] 16: 0x632a30 in -[UIWindow _sendTouchesForEvent:] 17: 0x632c56 in -[UIWindow sendEvent:] 18: 0x619384 in -[UIApplication sendEvent:] 19: 0x60caa9 in _UIApplicationHandleEvent 20: 0x1a95fa9 in PurpleEventCallback 21: 0x21811c5 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 22: 0x20e6022 in __CFRunLoopDoSource1 23: 0x20e490a in __CFRunLoopRun 24: 0x20e3db4 in CFRunLoopRunSpecific 25: 0x20e3ccb in CFRunLoopRunInMode 26: 0x1a94879 in GSEventRunModal 27: 0x1a9493e in GSEventRun 28: 0x60aa9b in UIApplicationMain 29: 0x20bb in main at /Users/.../main.m:14 30: 0x2065 in start
The code at line 186 of ViewElenco.m is the following:
ViewDettaglio *viewq=[[ViewDettaglio alloc] initWithNibName:@"ViewDettaglio" bundle:nil];
How can this happen?
I'm using a UINavigationController to navigate from ViewElenco and ViewDettaglio.
EDIT
Is it possibile that in the following code:
ViewDettaglio* viewDettaglio=[[ViewDettaglio alloc] initWithNibName:@"ViewDettaglio" bundle:nil]; viewDettaglio.idObject=idObj; [self.navigationController pushViewController:viewDettaglio animated:YES];
alloc returns a deallocated object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题已经解决:在ViewDettaglio和ViewElenco中有一个MKMapView,并且委托被设置为容器ViewController。
当在 UINavigationController 中推送新的 ViewController 时,MapView 创建的某些线程可能仍在运行并调用地图委托,即使它不可见。
解决方案是在视图消失时将 delegate 设置为 null,并在视图出现之前再次设置:
The problem has been solved: in ViewDettaglio and ViewElenco there was a MKMapView, and the delegate was set to the container ViewController.
When pushing a new ViewController in the UINavigationController, probably some thread created by MapView was still running and calling map delegate, even if it was not visible.
The solution was to set delegate to null when view will disapper, and set it again before view will appear: