代码之家  ›  专栏  ›  技术社区  ›  GuybrushThreepwood

帮助排除nszombie错误消息

  •  0
  • GuybrushThreepwood  · 技术社区  · 14 年前

    我有一个模态视图控制器,当它解散自己时,它会崩溃。错误是exc ou bad ou access(yipee)。我正在试着用nszombie来解决这个问题。我得到以下信息:

    2010-10-20 17:15:58.936[24058:207]在非零客户端计数上添加运行客户端启动设备 2010年10月20日17:16:06.846[24058:207] * -[ViewController保留]:消息发送到已释放实例0x6c2d4a0

    这意味着什么——这是意味着消息被发送到viewcontroller,还是意味着消息被发送到viewcontroller中的对象?

    我真的被卡住了,因为线似乎是主要的:(

    提前感谢您的帮助,

    马丁

    编辑

    感谢大家的快速回复。以下是我演示视图控制器的方式:

    -(IBAction)letsstartGame {
    
    ViewController * sl = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];  
    self.viewLink = sl;
    [sl release];
    
    [mainMenu stop];
    [mainMenu setCurrentTime:0.0];
    
    [self presentModalViewController:viewLink animated:NO];
    
    [viewLink release];
    self.viewLink = nil;
    

    }

    像这样解散:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    if (waitingOver) {
    
        [backgroundMain stop];
        [fireworks stop];
    
        [self dismissModalViewControllerAnimated:NO];
    
    }   
    

    }

    3 回复  |  直到 14 年前
        1
  •  2
  •   Dave DeLong    14 年前

    这意味着您有一个类型为的对象的实例 ViewController ,它被释放,然后你试图 retain 它。

    编辑

    你放的太多了。以下是您要做的:

    ViewController * sl = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];  //allocated, has a +1 retain count
    self.viewLink = sl;  //assuming a retain property, has a +2 retain count
    [sl release]; //releasing, now has +1 retain count
    ....    
    [viewLink release]; //releasing, now has a 0 retain count
    self.viewLink = nil; //attempting to release stale pointer, will result in a crash (perhaps not immediately, but eventually)
    

    摆脱 [viewLink release] 线。把它放在里面是不对的。

        2
  •  1
  •   Michael Chinen    14 年前

    这意味着您正在向解除分配的实例发送消息。 因此,在代码的某个地方,您未能保留对象(可能是viewcontroller)或过早地释放它。

    如果您可以将代码发布到您创建视图控制器的位置,这可能有助于我们进行调试。

        3
  •  1
  •   ACBurk    14 年前

    消息基本上是说,您正试图向已经解除锁定(释放并释放内存)的对象发送消息(调用函数)。如果您可以发送更多的代码,我可能会尝试确定原因。