【问题标题】:renderInContext creating memory that is not promptly releasedrenderInContext 创建没有及时释放的内存
【发布时间】:2011-02-16 15:25:53
【问题描述】:

在使用“ObjectAlloc”调试仪器时,我注意到为 renderInContext 调用分配了 7megs 的内存,但它从未被释放。当我注释掉 renderInContext 调用时,这不会发生,并且未来的 renderInContext 调用不会继续增加内存分配。

UIGraphicsBeginImageContext(contentHolder.bounds.size);
[contentHolder.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

有没有办法强制释放这段内存?

【问题讨论】:

  • 可能是图层拥有的缓存。如果/当你释放层会发生什么?
  • 我也面临同样的问题。有人知道它为什么会发生内存泄漏吗?
  • 当我开始为 4.2 编译时,我的问题消失了

标签: iphone memory core-graphics instruments


【解决方案1】:

我发现了如何释放 renderInContext 内存。只需在主线程上运行调用 renderInContext 的方法,就会自动释放分配的内存。

【讨论】:

  • 我不知道为什么 Apple 在不允许我们使用快 10 倍的 UIGetScreenImage 之后不解决这个问题。如果我们对 Retina iPad 进行捕获,UI 会因为 renderInContext 阻塞主线程而滞后。正如我在仪器中看到的那样,renderInContext 非常慢。
  • 此外,除了在非主线程上运行的 renderInContext 存在内存问题外,它在某些 iOS 6 视图(例如 MKMap 视图或使用 OpenGL ES 的任何视图)上也无法正常运行(它不会崩溃)在主线程中捕获地图)。它在视频子系统的深处崩溃。
猜你喜欢
  • 2014-01-06
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多