Skip to content Skip to sidebar Skip to footer

Outofmemoryerror When Loading Large Amount Of Data In Android

I'm downloading a rather large file on the SD card of an Android device (~60MB). The download goes fine, but I need to pull this file in its entirety into memory. I know that's a h

Solution 1:

Each Virtual Machine instance in Android has what they called a VM Budget. This basically is the max amount of memory the entire app can occupy and nothing more. getRuntime().maxMemory() will give you the vm budget size for your current instance.

The budget can go anywhere from 16MB (G1) to 48MB (Moto Xoom) I think. Those numbers could be different as I'm trying to remember off the top of my head.

Usually for something like this you'd read the data in as an InputStream and process the data as you read it but don't retain the data itself.

If this is a Bitmap. You can use...

BitmapFactory.Optionsoptions=newBitmapFactory.Options();
options.inSampleSize = 4; // Divides the width and height each by 4 when reading the data in.Bitmapbitmap= BitmapFactory.decodeFile(String "filePath", options);
Bitmapbitmap= BitmapFactory.decodeStream(InputStream "fileStream", options);

Solution 2:

The simple answer is: You should really reconsider your current design. Could you explain why you would need to load 60mb of data into memory?

Post a Comment for "Outofmemoryerror When Loading Large Amount Of Data In Android"