I am writing an Android application for a single specific phone (which just needs to run on my personal phone) and I need to make use of the following large array, which I want to use to efficiently convert RGB colors to HSV:
RainbowTable = new float[256*256*266][3];
The total size of this array should be 256*256*256*3*4B = 201326592B = 192MB.
When I debug the app, I get an out of memory exception, although approximately 300MB RAM are still free before its execution, according to the Android task manager.
I have already set the large-heap-option to true in the manifest file.
What can I do to prevent this error and preserve the needed amount of RAM?
EDIT: My phone is rooted, so maybe there is a possibility to increase the size of the memory heap per application.
Each device has a maximum per-app RAM cap. If this call in the manifest does not alleviate your problem:
Then your only other option is to write your code using the NDK. But that’s a pretty hefty thing to dive into, so I would try to figure out an alternative first.