Stresstest Memory on Android

旧巷老猫 提交于 2019-12-02 07:31:14

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.

You could try this app

https://play.google.com/store/apps/details?id=derekwilson.net.rameater

I am bias (I wrote it) but it works fine and is being used by a number of devs. No special permissions are required.

Android restricts each process to a maximum amount of memory (usually 500 MB but it can vary). Rameater gets around this by spawning a number of background services each of which can allocate memory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!