Large array - memory error
I'm writing an Android app for one specific phone (which just needs to be run on my personal phone) and I need to use the following large array that I want to use to convert RGB colors to HSV efficiently:
RainbowTable = new float[256*256*266][3];
The total size of this array should be 256 * 256 * 256 * 3 * 4B = 201326592B = 192 MB. When I debug the application, I get out of memory exception
though about 300MB of RAM is still free before executing it, according to Android Task Manager.
I have already set large-heap
-option to true
in my manifest file.
What can I do to prevent this error and save the required amount of RAM?
EDIT: my phone is rooted, so it might be possible to increase the memory heap size for each app.
source to share
Each device has a maximum cache memory for each application. If this call in the manifest doesn't ease your problem:
android:largeHeap="true"
Then your only option is to write your code with the NDK. But this is a pretty healthy thing to dive into, so I'll try to find an alternative first.
source to share
The maximum heap size is device dependent, and 192 MB is likely to be exceeded by devices currently allowed.
However, this answer indicates that you can use the NDK to allocate more memory.
source to share