Out of Memory on Android

edited April 2014 in Android Mode

Just sharing some advice about memory issues in Android.

I was getting "out of native memory" errors from the android Java VM.

My specific problem was that I was instantiating a lot of objects, each with their own loadImage() call. This was eating up all my memory and causing a crash whose cause wasn't apparent until I moved my project over to Eclipse which automatically reveals more detailed debug logging from Android and the use of memory examination tools with the MAT addon.

Remember that each image you load requires this many bytes: (width in pixels)(height in pixels)(4 bytes/pixel) of memory for the uncompressed bitmap. This can add up quite quickly in the restricted memory of Android.

So basically, use loadImage() as sparingly as possible. If you are using the same image in multiple objects, load it once at the global, sketch level, and then pass a reference to the image when you instantiate your objects.

Hopefully this will save someone the two weeks of hair pulling I just went through.

PS: this is a good resource for importing a Processing project into Eclipse: http://blog.onthewings.net/2013/04/25/setting-up-a-processing-android-project-in-eclipse/

Sign In or Register to comment.