How to free it?

I am creating a bitmap context, and in my code there is the following:

bitmapData = malloc(bitmapByteCount);

context = CGBitmapContextCreate (bitmapData,
                                     pixelsWidth,
                                     pixelsHeight,
                                     8,      // bits per component
                                     bitmapBytesPerRow,
                                     colorSpace,
                                     kCGImageAlphaPremultipliedFirst);

before the method returns a CGContextRef object, I think I should free bitmapData. Can I call safely free(bitmapData)before returning context?

+3
source share
2 answers

The documentation for CGBitmapContextCreateindicates the following:

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 problems.

NULL malloc'd, .

, CGBitmapContextCreate "create" , . - CFRelease().

+3

Jasarien , iOS 4.0 . , .

, . , bitmapData, Bad Things. bitmapData CFRelease . CGBitmapContextCreateImage CGImage , ... , CGImage .

, , , . , , , . , bitmapData ivars. , , , bitmapContext.

NULL bitmapData, iOS 4.0 . 4.0+ NULL, , , , CFRelease , .

+1

Source: https://habr.com/ru/post/1766172/


All Articles