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 can I fix this?