UIGraphicsGetImageFromCurrentImageContext泄漏

时间:2011-08-25 13:24:57

标签: ios image cocoa-touch memory memory-leaks

我编写了以下代码片段来拍摄屏幕快照:

UIGraphicsBeginImageContext(animationView.frame.size);
[[window layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是,UIGraphicsGetImageFromCurrentImageContext似乎正在泄露。这是对的吗?

在仪器中我无法得到确切的泄漏点。在活动监视器中,我观察到当我切换到执行上述代码片段的UI时,内存增量增加了几MB。在此之后它永远不会减少。 UIGraphicsGetImageFromCurrentImageContext有内存泄漏吗?我该如何解决这个问题?

修改

仪器分析 活动监视器:显示执行此行代码时的内存加标;即使在发布截图(UIImage)之后也永远不会减少

泄漏和分配,堆快照:不显示任何泄漏或此分配。

2 个答案:

答案 0 :(得分:-1)

您刚刚为您的animationView创建了一个包含数据的UIImage(可能是某些MB)。也许您应该将此功能包装在自动释放池中。

 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];     
    UIImage* screenshot = UIGraphicsGetImageFromCurrentImageContext();
    //[screenshot retain]; //If you want precise control over when it is released and you will use it later.
    [pool release];

答案 1 :(得分:-1)

CGContextRef context = UIGraphicsGetCurrentContext();

/ *您编码* /

CGContextRelease(上下文);

完成后清除上下文

相关问题