【发布时间】:2010-12-16 15:03:36
【问题描述】:
我有一个自定义视图,它使用以下方法绘制 CGImage:
- (void) drawImage
{
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
CGRect imageRect = {{0,0}, {CGImageGetWidth(image), CGImageGetHeight(image)}};
CGContextDrawImage(context, imageRect, image);
}
在调整视图大小时,进程使用的内存似乎在稳步增加(因此重复调用 drawImage)。 leaks 显示没有泄漏。 vmmap 确实显示内存增加,但在我的应用程序无法直接控制的区域,即 CG 栅格数据。
REGION TYPE [ VIRTUAL after open] [VIRTUAL after X resizes]
=========== [ =======]
ATS (font support) [ 31.7M] [ 31.7M]
CG backing stores [ 2448K] [ 5400K]
CG image [ 12K] [ 12K]
CG raster data [ 872K] [ 18.3M] <-- memory increase
更换
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
与
CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithWindow:[self window]] graphicsPort];
使泄漏消失,但会导致窗口重绘和视觉伪影变慢。
我该如何解决这个问题?
【问题讨论】:
标签: objective-c cocoa macos core-graphics