NSMutableArray EXC_BAD_EXCESS SIGBUS

发布于 2024-08-28 11:57:51 字数 405 浏览 3 评论 0原文

我有以下代码,它会在一段时间后导致崩溃,因为我在计时器中设置了以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月光色 2024-09-04 11:57:51

addObject:如果对象为零,将引发异常。试试这个:

array = [[NSMutableArray alloc] initWithCapacity:1]; //designated initializer
CGImageRef cgImage = UIGetScreenImage();
if(cgImage)
{
    [array addObject:cgImage];
    CGImageRelease(cgImage);
}

addObject: will raise an exception if the object is nil. Try this:

array = [[NSMutableArray alloc] initWithCapacity:1]; //designated initializer
CGImageRef cgImage = UIGetScreenImage();
if(cgImage)
{
    [array addObject:cgImage];
    CGImageRelease(cgImage);
}
虐人心 2024-09-04 11:57:51

从苹果开发者论坛到 UIGetScreenImage():

当您使用此功能时,请注意
它返回保留的 CGImageRef
并相应地管理你的记忆。

From the Apple Developer Forum to UIGetScreenImage():

As you use this function, please note
that it returns a retained CGImageRef
and manage your memory accordingly.

近箐 2024-09-04 11:57:51

您确定要发布 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文