如何避免使用xcode 4.5 w/o ARC的僵尸错误?

Chu*_*tte 6 memory-management objective-c ios automatic-ref-counting

当我在启用了僵尸的xcode 4.5.1(LLDB)调试器中运行我的应用程序(不使用ARC)时,在调用 - [super dealloc]( - [NSObject dealloc])时,我得到两次错误(2):

* - [V2APIClient class]:发送到解除分配的实例的消息0x9d865c0* - [V2APIClient class]:发送到解除分配的实例0x9d865c0的消息

当我在xcode 4.4.1(LLDB)调试器中运行相同的应用程序时,我收到错误消息一次(1).当我在XCode 4.3.2中运行相同应用程序的稍早版本时,我根本没有收到错误消息(0).我将使用相同/最新的代码重试此操作.

仅供参考-这似乎是完全一样的问题,因为这等后,至今尚未得到答复: - [Foo类]:发送到释放实例上的消息[超级的dealloc] )

我试图避免两次重复提出同样的问题,但我建议继续:https: //meta.stackexchange.com/questions/152226/avoiding-asking-a-question-thats-already-been-asked

另外,我刚刚在Apple开发者论坛中提出了相同的问题:https: //devforums.apple.com/thread/171282

最后,这是我班级的精髓:

@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
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题.我不相信我违反了任何内存管理规则,但这个错误似乎暗示不然.在解决这个问题之前,我对检查任何新代码犹豫不决.

谢谢,查克

ps对于记录,这是调用代码:

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
Run Code Online (Sandbox Code Playgroud)

bbu*_*bum 3

如果您正在向已释放的实例发送消息,那是因为您没有正确管理内存。您的释放未通过保留来平衡;过度释放。

首先,对您的代码进行“构建和分析”。修复发现的任何问题。

接下来,在启用了僵尸检测的仪器下运行并打开引用计数跟踪功能。然后,当它崩溃时,检查相关对象的所有保留/释放事件。您会发现一个额外的版本。挑战在于将保留插入正确的位置以平衡释放。

(正如 Rob 正确指出的那样,这可能只是额外调用释放的情况。)