NSMutableArray EXC_BAD_EXCESS SIGBUS
我有以下代码,它会在一段时间后导致崩溃,因为我在计时器中设置了以下代码:
CGImageRef cgImage = UIGetScreenImage();
[array addObject:(id)cgImage];
CGImageRelease(cgImage);
最初我将 array
声明为:
array = [[NSMutableArray alloc] init];
计时器运行良好,直到 10 秒,因为计时器已关闭1/10 秒 10 秒后崩溃。
我认为应用程序崩溃是因为 EXC_BAD_EXCESS
但不知道如何解决。 有人可以帮助解决这个问题吗?
感谢Adv。
I've the following code which causes crashes after sometime as i've set the below code in a timer:
CGImageRef cgImage = UIGetScreenImage();
[array addObject:(id)cgImage];
CGImageRelease(cgImage);
Where initiallly i've declared array
as:
array = [[NSMutableArray alloc] init];
The timer goes well till 10 seconds as timer is of 1/10 seconds after 10 seconds it crashes.
I think the application crashes because of EXC_BAD_EXCESS
but dont know how to solve.
Can anybody help in solving the problem?
Thanks in Adv.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
addObject:如果对象为零,将引发异常。试试这个:
addObject: will raise an exception if the object is nil. Try this:
从苹果开发者论坛到 UIGetScreenImage():
From the Apple Developer Forum to UIGetScreenImage():
您确定要发布 cgImage 吗?
我没有看到 UIGetScreenImage() 的文档,但如果它遵循 创建规则,我不希望你需要释放该对象(因为该函数没有“创建”或“复制”在其名称中)。
编辑:
此后,我发现了几个 参考文献,表明您确实 不管函数的名称如何,都需要释放图像。 (显然在 3.2 SDK 中已重命名为
UICreateScreenImage()
。Are you sure you're supposed to be releasing cgImage?
I don't see documentation for UIGetScreenImage(), but if it follows the Create Rule, I would not expect you to need to release the object (because the function does not have "Create" or "Copy" in its name).
EDIT:
I've since found several references that say that you do need to release the image, despite the name of the function. (Which has apparently been renamed
UICreateScreenImage()
in the 3.2 SDK.