xcode 消息发送到释放实例 0x141dafb0 iPhone SDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3676881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
message sent to deallocated instance 0x141dafb0 iPhone SDK
提问by Colby Swandale
i am getting this error "message sent to deallocated instance 0x141dafb0" its comming from a UIBarButtonItem when its beeing pressed on the application. any help would be greatly appreciated
我收到这个错误“消息发送到已释放的实例 0x141dafb0”,它来自 UIBarButtonItem,当它在应用程序上被按下时。任何帮助将不胜感激
Error:
错误:
*** -[PeerConnection performSelector:withObject:withObject:]: message sent to deallocated instance 0x14143ff0
PeerConnection.h
对等连接.h
#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>
@interface PeerConnection : NSObject <GKPeerPickerControllerDelegate, GKSessionDelegate> {
UIBarButtonItem *StartConnection;
}
- (IBAction) StartConnectionAction;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *StartConnection;
@end
PeerConnection.m
PeerConnection.m
#import "PeerConnection.h"
@implementation PeerConnection
@synthesize StartConnection;
- (IBAction) StartConnectionAction {
NSLog(@"Start Connection to the other IPhones");
[StartConnection release];
}
- (void)dealloc {
[super dealloc];
}
@end
i have enabled Zombie and that is all its giving to me
我启用了僵尸,这就是它给我的全部
回答by Dan Ray
Don't release your StartConnection
button until -dealloc
. Releasing that bar button item in -StartConnectionAction
is your problem--anything the UI tries to do with it after that will call a zombie.
在StartConnection
之前不要松开按钮-dealloc
。释放那个条形按钮项目-StartConnectionAction
是你的问题——在这之后 UI 试图用它做的任何事情都会调用一个僵尸。
回答by DELL
In your case, you have released the StartConnection object. Now, when the automatic dealloc is called, the reference was not found (as already removed) and hence you got the error.
在您的情况下,您已经释放了 StartConnection 对象。现在,当调用自动 dealloc 时,未找到引用(已删除),因此您收到错误。
回答by Gil Beyruth
I had the same error, but was using a singleton with autorelease on shared method, took off autorelease from there and added on it's dealloc , and all works fine now.
我有同样的错误,但在共享方法上使用带有 autorelease 的单例,从那里取消 autorelease 并添加它的 dealloc ,现在一切正常。
回答by Moe
Old Thread; But thought I might add.
旧线程;但我想我可能会补充。
If your app isn't using ARC; Use The Analyse Feature to find all the problems that may arise due to releasing/retaining objects.
如果您的应用未使用 ARC;使用分析功能查找由于释放/保留对象而可能出现的所有问题。
Shortcut is command + shift + B
快捷方式是 command + shift + B
Totally useful !
完全有用!
回答by DELL
This may be due to access of the instance that is already removed during GC. The error occurs in a case when you use autorelease.
这可能是由于访问了在 GC 期间已删除的实例。在使用 autorelease 的情况下会发生错误。
ThePlannerAppDelegate *delg = [(ThePlannerAppDelegate *)[[UIApplication sharedApplication] delegate] autorelease];
Now this is most likely the GC will destroy the reference although delg points to the main window delegate.
现在这很可能 GC 会破坏引用,尽管 delg 指向主窗口委托。
My point is use autorelease safely.
我的观点是安全地使用 autorelease。
Important: The error will occur when a message will be sent to an dead reference.
重要提示:将消息发送到死引用时将发生错误。