I’m creating an bitmap context, and in my code there is this:
bitmapData = malloc(bitmapByteCount);
context = CGBitmapContextCreate (bitmapData,
pixelsWidth,
pixelsHeight,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedFirst);
before the method returns the CGContextRef object, I think I must release the bitmapData. Can I safely call free(bitmapData) before I return the context?
The documentation for
CGBitmapContextCreatesays this:I would suggest you pass NULL instead of a malloc’d pointer and you will be free of worrying about its memory.
However, be mindful that
CGBitmapContextCreatehas ‘create’ in its name, so by convention you will own the object returned. You will need to release this at some point withCFRelease().