如果你需要bitmapData
不要释放它。如果您不需要它,请NULL
改为作为参数传递,Quartz 将自行分配内存(iOS 4.0 及更高版本)。
data: A pointer to the destination in memory where the drawing is to be rendered. The size of this memory block should be at least (bytesPerRow*height) bytes.
In iOS 4.0 and later, and Mac OS X v10.6 and later, you can pass NULL if you want Quartz to allocate memory for the bitmap. This frees you from managing your own memory, which reduces memory leak issues.
But Quartz doesn't copy bitmapData
, it does the rendering there. After you release context
you should free that memory.
Edit: In one of Apple sample projects, memory is freed, but not immediately:
float drawStage3(CGContextRef context, CGRect rect)
{
// ...
cachedData = malloc( (((ScaledToWidth * 32) + 7) / 8) * ScaledToHeight);
// ...
bitmapContext = CGBitmapContextCreate(cachedData /* data */,
// ...
CFRelease(bitmapContext);
// ...
// Clean up
CFRelease(cachedImage);
free(cachedData);
}