我正在用Cocos3D构建一个应用程序,需要相对大量的屏幕截图:
imgRef = tmpDrawingVisitor.renderSurface.createCGImage;
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDir = [paths objectAtIndex:0];
imgPath = [docDir stringByAppendingPathComponent: [[NSProcessInfo processInfo] globallyUniqueString]];
_flippingpath = [imgPath stringByAppendingPathExtension:@"png"];
//UIImage* uiImg= [UIImage imageWithCGImage: imgRef];
uiImgprep= [UIImage imageWithCGImage: imgRef];
//UIImage* uiImg= [UIImage imageWithCGImage: imgRef scale:0.5 orientation: UIImageOrientationUp];
uiImg = [self imageWithImage:uiImgprep scaledToSize:CGSizeMake(512.0, 384.0)];
imgData = UIImagePNGRepresentation(uiImg);
[imgData writeToFile: _flippingpath atomically: YES];我所做的是截图并将其保存到Document文件夹。之后,将其映射到CCSprite中,以便像翻书一样对其进行动画处理。
代码运行良好,但是内存累积起来(每次大约12 Mb),直到一个点的内存将会超载。
在这种情况下,我如何管理内存?我正在IOS 7.1.1中开发,它已经是ARC了。
发布于 2014-07-02 17:19:17
我不知道我是否正确理解了你的应用程序的作用,但如果我理解了,你有没有考虑过只在内存中保留当前页面的屏幕截图,上一页和下一页,因为这些是你唯一需要的。
内存中可能只有三个图像:
向前翻转时,您可以释放上一个,然后释放上一个=当前,然后分配下一个。当向后翻转时,您可以释放next,然后next = current,并分配previous。
因为你正在使用ARC来释放一个图像,所以只需确保你没有指向它的强指针引用。
我理解你的问题了吗?
https://stackoverflow.com/questions/24527129
复制相似问题