【问题标题】:message sent to deallocated instance 0x1edf5720 [closed]发送到已释放实例 0x1edf5720 的消息 [关闭]
【发布时间】:2013-05-24 05:53:34
【问题描述】:

当应用程序崩溃时,我在日志中收到以下消息

*** -[CFString release]: message sent to deallocated instance 0x1edf5720
[Switching to process 9223 thread 0x2407]
[Switching to process 9223 thread 0x2407]
[unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown](gdb)

我的问题很简单,我只想知道deallocated instance 0x1edf5720是哪一个。 我只是想知道是否有任何工具或某种方法可以让我知道 0x1edf5720 指的是哪个对象或僵尸确切创建的位置。请注意,我不能使用模拟器进行测试。我必须在设备上测试它。

提前致谢。

【问题讨论】:

  • 请发布您的代码并说出您想要做什么?当应用程序崩溃?以便人们可以提供帮助。
  • 使用 NSZombieEnabled 标志进行调试
  • 请将您的代码发布到崩溃的地方,并将代码粘贴到您的allocNSString
  • 我如何使用 NSZombieEnabled 标志以及它是如何工作的,你能解释一下吗?
  • @ankitmehta 请参考这个问题:stackoverflow.com/questions/1622079/…

标签: iphone memory-leaks


【解决方案1】:

这是崩溃应用程序的两个选项之一。

1.你没有分配NSString的变量,你release它。

2.您已经分配了autorelease 属性,如下所示..

   [[[NSString alloc] init] autorelease]; //Remove autorelease from here if you allocated with this keyword

使用NSZombieEnabled查看相关教程从此链接NSZombieEnabled-iPhone

【讨论】:

  • @ankitmehta 我还在上面的答案中添加了关于NSZombieEnabled 的链接,还可以查看我发布的上面的选项.. :)
  • 我添加了 NSZombieEnabled 参数,但我如何使用它来找出导致的对象?
  • 查看此链接stackoverflow.com/questions/2190227/… 并推荐给亲爱的 :) 希望它对您很有帮助...
【解决方案2】:

我认为您正在释放 NSString 而不分配它。

只有在分配值时才需要释放。

例如:

NSString * tempString=[[NSString alloc]init]; 

现在[tempString release]; 有效。

如果NSString * tempString=[NSString string];NSString * tempString=@"";

现在[tempString release]; 无效。

【讨论】:

  • 另一种说法是它被过度发布了。要么他向某个 autoreleased 变量(如您所说)发出了 release,要么以某种方式发出了额外的 release
猜你喜欢
  • 2013-12-04
  • 2011-06-16
  • 2023-03-13
  • 1970-01-01
相关资源
最近更新 更多