GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

callback function never gets called in CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rawImagePixels, sizeTBytesForImage, dataProviderRelease);

Open andrewzeus opened this issue 14 years ago • 3 comments

hi, Brad,

In GPUImageFilter.m file, through Instruments profiling, I can see significant memory leaks with -[GPUImageFilter imageFromCurrentlyProcessedOutput] as listed below.

Bytes Used Count Symbol Name 65.87 MB 100.0% 28805 * All Allocations * 60.96 MB 92.5% 2 Malloc 30.48 MB 60.96 MB 92.5% 2 -[GPUImageFilter imageFromCurrentlyProcessedOutput] 60.96 MB 92.5% 2 -[GPUImageFilter imageByFilteringImage:] 60.96 MB 92.5% 2 -[imageViewViewController makeGPUImageToonFilter:]

It turns out that the callback function of "CGDataProviderCreateWithData" never gets called to free rawImagePixels. Could you give it a try and set up a brkpt inside this callback function on your bench to see if it's getting called?

I am using ios5.0.1 on iphone4s. thanks a bunch in advance.

Andrew

GLubyte *rawImagePixels = (GLubyte *)malloc(totalBytesForImage);

CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rawImagePixels, sizeTBytesForImage, dataProviderRelease);

void dataProviderRelease (void *info, const void *data, size_t size) { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

NSLog(@"before: free malloc in GPUImageFilter");

free((void *)data);

 NSLog(@"after: free malloc in GPUImageFilter");
//free((void *)data);

}

andrewzeus avatar May 10 '12 09:05 andrewzeus

I just checked using the SimplePhotoFilter example, and both the iOS 5.0 texture cache callback (dataProviderUnlockCallback()) and the old data provider callback (dataProviderReleaseCallback()) are indeed properly triggered when taking a photo.

These callbacks are only triggered when the UIImage created from this pixel data is deallocated. The pixel data needs to be around for as long as the UIImage is, or you'll get a crash when you deallocate it out from under the image. Are you sure that you're not holding on to the UIImage somewhere?

As a note, you should be using -prepareForImageCapture on the filter you'll be getting the image from, so that on iOS 5.0 you can use the fast texture path for downloading images, which saves a lot of memory and is 20-40% faster.

BradLarson avatar May 10 '12 14:05 BradLarson

Isn't there supposed to be an ampersand before the callback (&dataProviderRelease)?

theoknock avatar Feb 05 '17 15:02 theoknock

Oh, one more thing: whether the callback gets called or not is moot in a multithreaded environment.

malloc doesn't free when whatever it allocates on one thread is deallocated on another. Wrap your code in this:

dispatch_async(dispatch_get_main_queue(), ^{

// malloc and whatever other code goes here...

});

theoknock avatar Feb 05 '17 16:02 theoknock