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 heap size an application can use. For example my tablet Samsung Galaxy Tab 8.9 P7310 can take up 64MB of memory.
Is there a way to increase this size of memory an application can use?
This question is related to
android
Use second process. Declare at AndroidManifest
new Service
with
android:process=":second"
Exchange between first and second process over BroadcastReceiver
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.
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
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.
Is there a way to increase this size of memory an application can use?
Applications running on API Level 11+ can have android:largeHeap="true"
on the <application>
element in the manifest to request a larger-than-normal heap size, and getLargeMemoryClass()
on ActivityManager
will tell you how big that heap is. However:
This only works on API Level 11+ (i.e., Honeycomb and beyond)
There is no guarantee how large the large heap will be
The user will perceive your large-heap request, because it will force their other apps out of RAM terminate other apps' processes to free up system RAM for use by your large heap
Because of #3, and the fact that I expect that android:largeHeap
will be abused, support for this may be abandoned in the future, or the user may be warned about this at install time (e.g., you will need to request a special permission for it)
Presently, this feature is lightly documented
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:
and here's a library i've made for it:
Source: Stackoverflow.com