开发者

CGContextDrawImage leak

I have a custom view that draws an CGImage using:

- (void) drawImage
{
    CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
    CGRect imageRect = {{0,0}, {CGImageGetWidth(image), CGImageGetHeight(image)}};
    CGContextDrawImage(context, imageRect, image);
}

It looks like the memory used by the process increases steadily when resizing the view (and thus repeatedly calling drawImage). leaks shows no leak. vmmap shows indeed a memory increase, but in an area which is outside my application's direct control, i.e. CG raster data.

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

Replacing

CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];

with

CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithWindow:[self window]] graphicsPort];

makes the leak go away but results in slower window redraws and visual artifacts.

How 开发者_StackOverflow社区can I fix this?


It doesn't seem like a leak, you are probably just increasing the size of a cache. You say it peaks at 50Mb and seem to think it will be 50Mb per document but it may simply be 50Mb per process.


Not to be dismissive but do you really have a problem here? Leaks is all clear, 18.3M isn't very much VM for CG raster data. If you resize the window for long enough will it really consume all available memory? How have you shown this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜