Search code examples
javaandroidtestingstress-testing

Stresstest Memory on Android


Is it possible to stresstest an Android system to check what happens if available memory decreases (and therefor which applications are killed, ...).

I currently have a testing application that periodically allocates 10MB in a vector. But an OutOfMemory exception is thrown reaching 500MB. But the system under test was not influenced sufficiently. I need to aquire even more memory.

Are there any known libraries/programs to use or is there any other method that let an application use more memory than 500MB.

Add: I'm already using android:largeHeap="true" in my manifest.


Solution

  • Other than rooting the device and hacking the way Android allocates a memory limit to running applications, there is no way to increase the limit of memory using native Java code.

    However(!), using a C++ library via JNI allows you to circumvent this limitation. All memory allocated on this layer has access to the overall memory pool of the device, rather than the sandboxed pool native applications get.

    As an example for this, look at OpenGL. Normally, you could maybe hold 4-5 bitmaps sized 1024x1024 in memory before getting an OutOfMemory exception. However, if each time you create a bitmap, you transform it into an OpenGL texture (which is managed in the native C++ library) and then destroy the bitmap, you'll find that you can hold a huge amount of pictures before reaching the device's memory limit.

    Similarly, if you create such a C++ library, and link it to your project via JNI, you could theoretically hold a massive buffer inside the library, and use the Java code to append more data, or extract a portion of the data when needed.