HardwareAccelerated, largeHeap analysis

The problem

I have encountered OOM exceptions before, but it does require so much memory.

Throwing OutOfMemoryError failed to allocate a 42793710 byte with 52488 free bytes and 22MB until OOM

To solve

See a post on the prompt to add the following code, unexpectedly magical good.

android:hardwareAccelerated="false"
android:largeHeap="true"
Copy the code

Analysis of the

HardwareAccelerated true will enable faster loading of interfaces that have a lot of image analogies. But watch out for the memory increase that comes with setting this option. If the largeHeap is true, it is requesting more memory from the system. We know that Android has a memory usage limit for each application, the machine’s memory limit, configured in the /system/build.prop file.

dalvik.vm.heapsize=128m  
dalvik.vm.heapgrowthlimit=64m 
Copy the code

Heapgrowthlimit is a common application memory limit, use ActivityManager. GetLargeMemoryClass value is the (). Heapsize is the maximum memory value that can be used after largeHeap=true is set in the manifest. Setting largeHeap does increase the amount of memory requisition. However, it is not possible to apply as much memory as the system has, but is limited by dalvik.vm. Heapsize.

In the end

This method is only a stopgap measure, but programmers should consider memory usage as the most important