Phonegap/Cordova out of memory when taking photos

I was having an issue with phonegap where an application on a specific phone would randomly crash after selecting a photo for uploading.

I installed ACRA ( ) so the phone can send a dump when it crashes.

This turned out to be quite useful. The dump contained this part of interest

STACK_TRACE => java.lang.OutOfMemoryError: (Heap Size=23267KB, Allocated=5377KB)
at Method)

The phone is running out of memory when it tries to manipulate images.

After some research it seems that Android likes to load the entire image into memory using a bitmap format to manipulate it. This includes changing the image quality.

I had the image quality set to 50% to reduce upload time. But in order to change the quality, the phone has to load it into memory, make the changes, then save it out again for upload.

So the quick and easy fix for this is to not do any image manipulation. Set the image quality to 100%, and make sure image rotation is set to false.


function capturePhoto() {, onFail, {
		quality: 100,
		destinationType: destinationType.FILE_URI,
		correctOrientation: false,
		saveToPhotoAlbum: true