有人可以帮我了解一下iPhone应用程序中的堆栈跟踪吗? [英] Can somebody give me a hand about this stacktrace in iPhone app?

查看:82
本文介绍了有人可以帮我了解一下iPhone应用程序中的堆栈跟踪吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Program received signal:  "EXC_BAD_ACCESS".
(gdb) bt
#0  0x30011940 in objc_msgSend ()
#1  0x30235f24 in CFRelease ()
#2  0x308f497c in -[UIImage dealloc] ()
#3  0x30236b78 in -[NSObject release] ()
#4  0x30a002a0 in FlushNamedImage ()
#5  0x30250a26 in CFDictionaryApplyFunction ()
#6  0x30a001a4 in _UISharedImageFlushAll ()
#7  0x30a00738 in +[UIImage(UIImageInternal) _flushCacheOnMemoryWarning:] ()
#8  0x3054dc80 in _nsnote_callback ()
#9  0x3024ea58 in _CFXNotificationPostNotification ()
#10 0x3054b85a in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
#11 0x3054dbc0 in -[NSNotificationCenter postNotificationName:object:] ()
#12 0x30a00710 in -[UIApplication _performMemoryWarning] ()
#13 0x30a006a8 in -[UIApplication _receivedMemoryNotification] ()
#14 0x30a005d8 in _memoryStatusChanged ()
#15 0x30217416 in __CFNotificationCenterDarwinCallBack ()
#16 0x3020d0b0 in __CFMachPortPerform ()
#17 0x30254a76 in CFRunLoopRunSpecific ()
#18 0x3025416a in CFRunLoopRunInMode ()
#19 0x320452a4 in GSEventRunModal ()
#20 0x308f037c in -[UIApplication _run] ()
#21 0x308eea94 in UIApplicationMain ()
#22 0x00002096 in main (argc=1, argv=0x2ffff514)

当前我我的程序中有一个非常奇怪的错误。有时会发生,有时则不会。但是,这里是发生的事情的摘要:

Currently I have a very weird error in my program. Sometimes it happens, and sometimes, it doesn't. But here's a summary of what's going on:

程序启动时:


  • 保存的数据(只是一个短的plist由13个元素组成)如果存在将被加载。

  • 将包含1014个字符串的巨大plist加载到NSMutableDictionary中。

  • 另一个包含78个字符串的plist加载到NSArray中。

  • 播放.mp4电影。

  • saved data (just a short plist consists of 13 elements) is loaded if it exists.
  • a huge plist containing 1014 strings is loaded into NSMutableDictionary.
  • another plist containing 78 strings is loaded into an NSArray.
  • a .mp4 movie is played.

该错误发生在删除OpenGL ES视图并且用户将要查看NSMutableDictionary中1014字符串之一的部分。

The error occurs at a part where OpenGL ES View is being removed and the user is about to view one of the strings of the 1014 strings in the NSMutableDictionary.

在模拟器中永远不会发生此错误。它仅出现在iPhone上,有时运行良好,但有时会崩溃。

This error never occur in the simulator. It only occur on the iPhone, and sometimes it runs fine but sometimes it crushes.

但是,在阅读了堆栈跟踪之后,我看到了CFDictionaryApplyFunction,所以我认为可能是可能的原因之一。是因为在模拟器上读取速度如此之快,以至于plist中的整个字典都立即加载了,而在设备上读取速度却很慢?老实说,我不完全了解字典的工作方式。它是立即读取所有1014字符串,还是使用其他线程读取速度很慢?请指教。谢谢。

However, after reading the stacktrace, I see CFDictionaryApplyFunction in there, so I thought it might be one of the possible causes. Is it because on the simulator, it reads things so fast that the whole dictionary from the plist is loaded at an instant, while on the device, it reads slower? Honestly, I do not know exactly how the dictionary works. Does it read through all 1014 strings at an instant, or it uses some other threads to read slowly? Please advice. Thank you.

推荐答案

当您获得 EXC_BAD_ACCESS 时,通常意味着您试图在不存在的对象上调用方法-可能是因为它已被释放。

When you get an EXC_BAD_ACCESS, it often means you're trying to call a method on an object that isn't there -- probably because it's been deallocated.

大约在跟踪的一半处,有一些内存警告调用,例如:

About halfway down the trace, there are some memory warning calls, such as:

#12 0x30a00710 in -[UIApplication _performMemoryWarning] ()

这似乎表明您的代码都不是直接直接导致崩溃的,而是

Which makes it appear that none of your code is directly causing the crash, but rather a system notification when memory runs low.

更接近第0帧,它似乎正试图清除 UIImage 对象,这似乎是错误的访问。

Closer to frame #0, it appears to be attempting to clear the cache of a UIImage object, and this appears to be the bad access.

基于此,一种猜测是您正在为自动释放的返回值分配一个指针。便利构造函数;然后该对象会自动释放,您可能会认为很好,因为您没有直接使用图片,但是内存警告尝试访问它。例如:

Based on this, one guess is that you're assigning a pointer to the autoreleased return value of a convenience constructor; then the object is autoreleased, and you might think it's fine because you don't use the image directly, but the memory warning tries to access it. For example:

@interface MyClass {
  UIImage* myImage;
}
// ...
- (id) init {  /* the usual stuff */
  myImage = [UIImage imageNamed:@"bob_the.png"];
  return self;
}

在此示例中,即使您在<$上设置了保留属性c $ c> myImage ,除非您通过 self.myImage 设置值,否则实际上并没有保留图像。因此,在此调用之后不久,该图像被释放,并且您有一个指向没有人的土地的指针。

In this example, even if you have a retain property set up on myImage, you're not actually retaining the image unless you set the value via self.myImage. So, shortly after this call, the image is released, and you've got a pointer to no man's land.

在没有看到代码的情况下,我无法知道

Without seeing the code, I have no way of knowing if that's what's actually going on, but it's one type of mistake that's easy to make.

这些相关问题为类似的崩溃提供了提示: EXC_BAD_ACCESS 调试 问题1 问题2

These related questions give tips on similar crashes: EXC_BAD_ACCESS debugging question 1 and question 2.

最后,如果没有帮助,我建议您找到问题的最小复制量。做到这一点的困难方法是复制代码,剪掉一半,看看错误是否仍然存在,然后重复执行直到获得最小的代码为止,然后找到能重现错误的代码。通常,从那里进行调试要容易得多(作为堆栈溢出问题也可以发布!)如果您知道简单的方法,请告诉我。

Finally, if none of that helps, I suggest finding a minimal reproduction of your problem. The hard way to do this is to copy your code, cut out half, see if the error is still there, and repeat until you get the smallest code you can find which reproduces the error. It's usually a lot easier to debug from there (and more postable as a stackoverflow question, too!) If you know the easy way, let me know.

这篇关于有人可以帮我了解一下iPhone应用程序中的堆栈跟踪吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆