当我在启用僵尸的 xcode 4.5.1 (LLDB) 调试器中运行不使用 ARC 的应用程序时,在调用 -[super dealloc] (-[NSObject dealloc] ):
* -[V2APIClient 类]:发送到已释放实例 0x9d865c0 的消息 * -[V2APIClient 类]: 发送到释放实例 0x9d865c0 的消息
当我在 xcode 4.4.1 (LLDB) 调试器中运行相同的应用程序时,我收到一次错误消息 (1)。 当我在 XCode 4.3.2 中运行同一应用程序的稍早版本时,我根本没有收到错误消息 (0)。我将使用相同/最新的代码重试。
仅供引用 - 这似乎与另一篇尚未得到解答的帖子完全相同的问题: -[Foo class]: message sent to deallocated instance on [super dealloc] )
我试图避免重复发布同一个问题,但有人建议我继续: https://meta.stackexchange.com/questions/152226/avoiding-asking-a-question-thats-already-been-asked
此外,我还在 Apple Developer Forums 中提出了类似的问题: https://devforums.apple.com/thread/171282
最后,这是我的类(class)的精髓:
@interface ASIHTTPRequestHandler : NSObject {
id _error;
}
@property (nonatomic,retain) id error;
@end
@implementation ASIHTTPRequestHandler
@synthesize error = _error;
-(id)init
{
self = [super init];
if (self)
{
self.error = nil;
}
return self;
}
-(void)dealloc
{
self.error = nil;
[super dealloc];// this is the line that appears to cause the problems
}
@end
请帮我解决这个问题。 我不相信我违反了任何内存管理规则,但这个错误似乎暗示并非如此。在解决此问题之前,我对是否 checkin 任何新代码犹豫不决。
谢谢, 查克
附注作为记录,这里是调用代码:
PanoTourMgrAppDelegate *ptmAppDlgt = [PanoTourMgrAppDelegate getApplicationDelegate];
Settings *settings = ptmAppDlgt.settings;
Identification *identification = ptmAppDlgt.identification;
V2APIClient *v2ApiClient = [[V2APIClient alloc] initWithSettings:settings identification:identification];
NSDictionary *result = [v2ApiClient get_application_status];
BOOL success = [v2ApiClient callWasSuccessful:result];
if (!success)
{
id error = v2ApiClient.error;
NSString *mbTitle = nil;
NSString *mbMessage=nil;
if ([error isKindOfClass:[NSString class]])
{
mbTitle = @"Application version no longer suppported";
mbMessage = (NSString*)error;
[MessageBox showWithTitle:mbTitle message:mbMessage];
}
}
[v2ApiClient release]; // This is the line that indirectly causes the messages above
最佳答案
如果您正在向已解除分配的实例发送消息,那是因为您没有正确管理内存。你有没有被保留平衡的释放;过度释放。
首先,对您的代码进行“构建和分析”。修复发现的任何问题。
接下来,在启用僵尸检测的 Instruments 下运行,并打开引用计数跟踪功能。然后,当它崩溃时,检查有关对象的所有保留/释放事件。你会发现一个额外的版本。挑战在于将保留插入正确的位置以平衡发布。
(正如 Rob 正确指出的那样,这可能只是额外调用 release 的情况。)
关于objective-c - 如何避免 xcode 4.5 w/o ARC 出现僵尸错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13018251/