释放NSKeyedUnarchiver导致崩溃

|
-(id)func
{
        NSData* data = [[NSData alloc] initWithContentsOfFile:aFilePath];
    NSKeyedUnarchiver* unachiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
    id object = [unachiver decodeObjectForKey:key];
    [unachiver finishDecoding];
        [unachiver release];
        [data release];
    return object;
}
调用此方法时,例如:
id anotherObject = [self func];
然后,当我将消息发送到anotherObject时,它将导致崩溃,我知道它是一个悬挂指针,但是我不知道如何解决它。     
已邀请:
decodeObjectForKey:
返回一个自动释放的对象。到向
anotherObject
发送消息时,该消息已被取消分配。要停止此操作,您需要确保在拥有该对象时将其“ 4”个对象:
id anotherObject = [[self func] retain];
完成对象处理后,应调用ѭ6以确保释放它。     

要回复问题请先登录注册