I am writing an Android application which uses several 3D models. Such a model with textures can take up a lot of memory. I found out the manufacturer sets a limit on the he
Use second process. Declare at AndroidManifest
new Service
with
android:process=":second"
Exchange between first and second process over BroadcastReceiver
This can be done by two ways according to your Android OS.
android:largeHeap="true"
in application tag of Android manifest to request a larger heap size, but this will not work on any pre Honeycomb devices.VMRuntime.getRuntime().setMinimumHeapSize(BIGGER_SIZE);
Before Setting HeapSize make sure that you have entered the appropriate size which will not affect other application or OS functionality. Before settings just check how much size your app takes & then set the size just to fulfill your job. Dont use so much of memory otherwise other apps might affect.
Reference: http://dwij.co.in/increase-heap-size-of-android-application
you can't increase the heap size dynamically.
you can request to use more by using android:largeHeap="true"
in the manifest.
also, you can use native memory (NDK & JNI)
, so you actually bypass the heap size limitation.
here are some posts i've made about it:
How to cache bitmaps into native memory
JNI bitmap operations , for helping to avoid OOM when using large images
and here's a library i've made for it:
Increasing Java Heap unfairly eats deficit mobile resurces. Sometimes it is sufficient to just wait for garbage collector and then resume your operations after heap space is reduced. Use this static method then.
From what I remember you could use VMRuntime
class in early Android versions but now you just can't anymore.
I don't think letting the developer choose the heap size in a mobile environment can be considered so safe though. I think it's easier that you can find a way to modify the heap size in a specific device (not on the programming side) that by trying to modify it from the application itself.
You can use android:largeHeap="true" to request a larger heap size, but this will not work on any pre Honeycomb devices. On pre 2.3 devices, you can use the VMRuntime class, but this will not work on Gingerbread and above.
The only way to have as large a limit as possible is to do memory intensive tasks via the NDK, as the NDK does not impose memory limits like the SDK.
Alternatively, you could only load the part of the model that is currently in view, and load the rest as you need it, while removing the unused parts from memory. However, this may not be possible, depending on your app.