我这里有内存管理问题吗?

发布于 2024-08-24 08:10:08 字数 522 浏览 2 评论 0原文

这里的代码一定有问题:

+ (UIImage*)captureView:(UIView *)theView {
    UIGraphicsBeginImageContext(theView.frame.size);
    [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

当我使用它时,Xcode 向我抛出以下错误消息:

malloc:* 对象错误 0x103f000:未释放指针 已分配 *在malloc_error_break中设置断点进行调试

我在那里看不到任何内存管理错误。还有其他人吗?

Something must be wrong with this code right here:

+ (UIImage*)captureView:(UIView *)theView {
    UIGraphicsBeginImageContext(theView.frame.size);
    [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

When I use that, Xcode throws me this error message:

malloc: * error for object
0x103f000: pointer being freed was not
allocated
*
set a breakpoint in malloc_error_break to debug

I can't see any memory management errors there. Does anyone else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

独夜无伴 2024-08-31 08:10:08

我也有同样的警告。但是,在 3.1 或更高版本中不会出现这种情况。

I had the same warning. But, it does not occur in 3.1 or above.

柠北森屋 2024-08-31 08:10:08

别看。在构建中设置启用 NSZombie 来追踪它。

它可能与从类方法返回自动释放的 UIImage 有关,该方法可能位于临时自动释放池内。该图像可能会因该池的排水而被破坏。要进行测试,请将方法移至实例方法并查看问题是否消失。

Don't see. Set NSZombie enabled in the build to track it down.

It might be related to returning an autoreleased UIImage from a class method which will probably be inside of a temporary autorelease pool. The image might be being destroyed by the draining of that pool. To test, move the method to an instance method and see if the problem goes away.

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