How to work around Android’s 24 MB memory limit

转载 2012年10月25日 10:42:41

The Android framework enforces a per-process 24 MB memory limit. On some older devices, such as the G1, the limit is even lower at 16 MB.

What’s more, the memory used by Bitmaps is included in the limit. For an application manipulating images it is pretty easy to reach this limit and get the process killed with an OOM exception:

E/dalvikvm-heap(12517): 1048576-byte external allocation too large for this process.

E/GraphicsJNI(12517): VM won't let us allocate 1048576 bytes

D/AndroidRuntime(12517): Shutting down VM

W/dalvikvm(12517): threadid=1: thread exiting with uncaught exception (group=0x4001d7f0)

E/AndroidRuntime(12517): FATAL EXCEPTION: main

E/AndroidRuntime(12517): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

This limit is ridiculously low. For a device, like the Nexus One, with 512MB of physical RAM, setting the per-process memory limit for the foreground activity to only 5% of the RAM is a silly mistake. But anyway, that’s how things are and we have to live with it — i.e. find how to work around it.

There are two ways to allocate much more memory than the limit:

One way is to allocate memory from native code. Using the NDK (native development kit) and JNI, it’s possible to allocate memory from the C level (e.g. malloc/free or new/delete), and such allocations are not counted towards the 24 MB limit. It’s true, allocating memory from native code is not as convenient as from Java, but it can be used to store some large amounts of data in RAM (even image data).

Another way, which works well for images, is to use OpenGL textures — the texture memory is not counted towards the limit.

To see how much memory your app has really allocated you can use android.os.Debug.getNativeHeapAllocatedSize().

Using either of the two techniques presented above, on a Nexus One, I could easily allocate 300MB for a single foreground process — more than 10 times the default 24 MB limit.

How to work around a possible XNA Game Studio or Windows Phone SDK install failure on Windows 8

As announced earlier today on the Building Windows 8 blog, a Windows 8 consumer preview is avail...

How to increase MySQL memory limit?

The question – I have a lot of RAM on my machine. How can I increase the memory limits used by MySQL...
  • boy317
  • boy317
  • 2016年09月27日 11:20
  • 155

How to Increase the Memory Limit for 32-bit Applications in Windows 64-bit OS

1. Go to Control Panel, and click view by “small icons” in the top right hand corner 2. Click Syste...

ccah-500 第9题 How would you tune your io.sort.mb value to achieve maximum memory to disk I/O ratio?

9.You observed that the number of spilled records from Map tasks far exceeds the number of map out...

Sicily 找中位数(Memory Limit:2MB)

Description   给出一个含有N个数的无序数组,找出数列的中位数。当N是偶数,则中位数是数列排序后中间两个数的平均数;若N是奇数,则中位数就是数列排序后中间的那个数假设数组下标从0开始...

How to discover memory usage of my application in Android

I would like to know how I can find the memory used on my Android application, programmatically. ...

Android Memory Management, OutOfMemoryError(转来看看) Android框 架强制每个进程的24 MB内存限制。在一些旧的设备,如在G1,限制为16 MB 更

Android框 架强制每个进程的24 MB内存限制。在一些旧的设备,如在G1,限制为16 MB 更低,更重要的是,由位图使用的内存限制。处理图像的应用程序,它是很容易达到此限制,并获得与OOM ...

【iMX6QD】 How to Add 24-bit LVDS Support in Android

目录(?)[+] Introduction   LVDS display panel driving data flow: Display quality: To get...

How Does Excel’s RTD Function Work ?

Excel has a function called RTD the enables a user to update a spreadsheet with real-time data. with...

1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 337 Solved:

1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 337  Solved:...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to work around Android’s 24 MB memory limit
举报原因:
原因补充:

(最多只允许输入30个字)