GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Memory warning while saving photos in camera roll

Open aliasdoc opened this issue 14 years ago • 5 comments

I'm using GPUImageFilterPipeline and while I use AssertLibrary to save photo in camera roll, it success but I receive a memory warning and if i retry to still photo, it crash.

I use 2 filters (transform and rotation) and add 3 filters (vignette, contrast, exposure) with GPUImageFilterPipeline. To still photo I call [GPUImageStillCamera capturePhotoProcessedUpToFilter:] with [[GPUImageFilterPipeline filters] lastObject] argument.

aliasdoc avatar Apr 03 '12 20:04 aliasdoc

What is the size of the photo and what device was this on?

BradLarson avatar Apr 04 '12 16:04 BradLarson

Hi Brad, my device is iPhone 4S running iOS5.1. I init GPUImageStillCamera with default preset AVCaptureSessionPresetPhoto, the size of photos is 2448x3264 (8.0Mp) (2.16Mb). Sometimes, it freeze my phone.

aliasdoc avatar Apr 04 '12 17:04 aliasdoc

I've made some significant improvements to the memory usage during image capture. To enable these new features, you need to call -prepareForImageCapture on the last filter in your pipeline when you first set it up. This will allow for direct memory reads of the texture at that stage, which cuts memory usage by more than half. In my experience, it eliminates memory warnings when saving photos on an iPhone 4S.

Since this and issue #69 cover the same ground, I'm closing this one. If you are still having problems, feel free to discuss this in the other issue:

https://github.com/BradLarson/GPUImage/issues/69

BradLarson avatar Apr 22 '12 03:04 BradLarson

Hi Brad,

Still having the same issue here on last build (downloaded 28/04/2012).

On iPhone4S i just used the SimplePhotoFilter example and after shooting 4/5 photos, the console give me the message:

2012-04-28 18:48:21.261 SimplePhotoFilter[5302:707] Received memory warning. 2012-04-28 18:48:23.628 SimplePhotoFilter[5302:707] Received memory warning.

And the app terminate due to low memory.

c.

valvoline avatar Apr 28 '12 17:04 valvoline

The reason for that was that the saving of the photos to the library is an asynchronous process that can take several seconds. The photo is in memory while it is being written to disk, so if you take another photo at the same time, and try to save it, it also will go into memory. Adding a third or fourth photo being saved in this manner is enough to trigger a memory warning and crash.

To prevent this, I recommend only allowing one photo at a time to be saved to the library. In the SimplePhotoFilter example, I've now added code to disable the photo taking button while the previous photo is still being saved, then reenable it once the save has finished and the memory from that old photo has been freed. This keeps the memory usage for the application within a safe range.

BradLarson avatar Apr 28 '12 21:04 BradLarson