[英]iPhone - When CGDataProviderRef is released does it destroy dynamical fields
I have created CGDataProviderRef, and one of parameters is array of pixels. 我创建了CGDataProviderRef,其中一个参数是像素数组。 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. 当您已经将数据保存在NSData对象中时,可以改用CGDataProviderCreateWithCFData,这样就不必malloc和复制像素。
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: 如果您坚持使用malloc数组,则可以提供一个在数据提供者发布时调用的回调,如下所示:
void freePixels(void *info, const void *data, size_t size) {
free((void*)data);
}
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, [data length], freePixels);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.