简体   繁体   中英

iPhone - When CGDataProviderRef is released does it destroy dynamical fields

I have created CGDataProviderRef, and one of parameters is array of pixels. When I release provider, do i also have to free memory, or is provider doing it itself?

pixels = (Byte *) malloc([data length] * sizeof (Byte));   
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, [data length], NULL);

Basically, do i have to call:

[provider release];
[free pixels];

When you already have your data in an NSData object you can instead use CGDataProviderCreateWithCFData, so you don't have to malloc and copy the pixels.

If you insist on using a malloc'd array you can provide a callback that is called when the data provider is released like this:

void freePixels(void *info, const void *data, size_t size) {
    free((void*)data);
}

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, [data length], freePixels);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM