1

当我使用以下代码获取视图快照时,当我导航到视图并返回上一个视图时,它会一次又一次地分配 12MB 内存。

 UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
 [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

在使用仪器进行分析时,我知道 CGRaster Data 对此负责?如何解决这个问题?

4

1 回答 1

0

嗨,试着把你的代码放到autoreleasepool.

@autoreleasepool
{
   UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
   [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
}
于 2014-08-31T18:29:03.223 回答