Did you try the android:largeHeap
in your manifest. This flag indicates to the system that your app might need a bigger memory heap than that is allocated to a regular app. The system however takes the final call based on the overall memory size available on the device. Google doc says -
android:largeHeap
Whether your application's processes should be
created with a large Dalvik heap. This applies to all processes
created for the application. It only applies to the first application
loaded into a process; if you're using a shared user ID to allow
multiple applications to use a process, they all must use this option
consistently or they will have unpredictable results. Most apps should
not need this and should instead focus on reducing their overall
memory usage for improved performance. Enabling this also does not
guarantee a fixed increase in available memory, because some devices
are constrained by their total available memory.
To query the available memory size at runtime, use the methods
getMemoryClass() or getLargeMemoryClass().
So for your purpose, since you a need a bigger heap, this will definitely help.
Now this obviously does not answer the question, why getMemoryClass
is returning 256 MB while garbage collection is happening at 128 MB (may be the system is keeping a too wide buffer). What I will suggest is you to print the return value of another method on ActivityManager
which is getLargeMemoryClass
. This along with turning largeHeap
might provide some clues