Trick to use largeHeap for older androids <3?

When I tried to allocate more than approx. 30 MB on Android 2.3 (Samsung Galaxy 1) for my graphic hopper project I encountered OutOfMemory errors. But I found out that for applications like Firefox and skobbler on the same device, it is somehow possible to allocate more than 80 MB! At least I saw a used memory of 90 or even 120 MB in the task manager!

I found that newer versions of Android> = 3 allow you to set the big heap flag (largeHeap = true), but how do the guys from Firefox do this for Android 2.3?

+4
source share
1 answer

I think it is possible that these applications use internal memory, which may exceed the limit (they request memory from their own code).

It should be possible to do this even without inline code using ByteBuffer and call allocateDirect. This can be verified using this hack .

Update Unfortunately, this is only possible through native code in accordance with this post . They wrapped this in a java call. But for the Delyan commentator, the following Java hack for image processing is suggested:

 BitmapFactory.Options opts = new BitmapFactory.Options(); Field field = opts.getClass().getField("inNativeAlloc"); field.setBoolean(opts, true); 

but: "At the same time, remember that this is dangerous . If the device runs out of memory, oomkiller comes after you first. There is no warning, nothing but SIGKILL., more than ever, recycle everything that you do not need, and be very, very careful! "

Update 2 In the end, we can crack through reflection access to sun.misc.Unsafe , as is done in the popular Java-Chronicle Project ?

+2
source

All Articles