【问题标题】:memory crash when i try to stopAnimating UIActivityIndicatorView当我尝试停止动画 UIActivityIndi​​catorView 时内存崩溃
【发布时间】:2012-04-13 13:03:57
【问题描述】:

当我尝试从线程更新 UIActivityIndi​​catorView 时。应用程序因抛出异常而崩溃 正在完成的修改层 - 0x7e177fd0 -[CALayer removeAnimationForKey:]:消息发送到释放的实例 0x7e177fd0 。 当我尝试从 mallocDebugger 工具中跟踪内存泄漏时。

这种崩溃并非总是发生 1/10

请帮我解决这个内存问题

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

[autoRechargeCell addSubview:activityIndicator];
[self.activityIndicator startAnimating];
   if( [PennyTalkAPI getBalanceInfoForAccount:appDelegate.accountNumber withPIN:appDelegate.pinNumber])
{   
    [autoRechargeCell.switchField setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"AutoRecharge"]];
    [self.activityIndicator stopAnimating];   <<<<<<<<<<<<<<<<<<<<<< 

}
else
{
    [self.activityIndicator stopAnimating];
}

[pool release]; 

这是我写的代码

【问题讨论】:

  • 请贴出你的部分代码。
  • NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; [autoRechargeCell addSubview:activityIndi​​cator]; [self.activityIndi​​cator startAnimating]; if([PennyTalkAPI getBalanceInfoForAccount:appDelegate.accountNumber withPIN:appDelegate.pinNumber]) { [autoRechargeCell.switchField setOn:[[NSUserDefaults standardUserDefaults] boolForKey:@"AutoRecharge"]]; [self.activityIndi​​cator stopAnimating]; } else { [self.activityIndi​​cator stopAnimating]; } [池释放];
  • 这是我写的代码

标签: iphone


【解决方案1】:

如果不查看代码并看到错误,我假设您释放了您的活动指示器,然后您尝试访问它以制作动画..

解决方法:在.h文件中声明UIActivityIndicator对象,在-(void)dealloc方法中合成并释放。

【讨论】:

  • 如果它只在你的一个类中使用,你为什么要合成它?只需要遵循正确的内存管理程序
  • @NickBull:是的。谢谢提示。无需合成,只需在适当的时间和地点发布即可。 :-))
  • 我只在 dealloc 方法中发布它
【解决方案2】:

这要么是双重释放错误,要么是悬空指针。您应该在 Scheme 的配置中启用僵尸检测,并尝试在 Instruments 中使用 Zombies 工具。

【讨论】:

  • 我正在尝试通过启用 NSZombies 和 malloc guard 。我还没有发布我的活动指标
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多