Bitmap OOM caused by Android frame animation (risk points brought by foreign sdk)

In the background of bugly, an OOM of the java layer appeared on a channel package of App Store.

Java heap memory oom has two situations :

  • One is that the heap memory occupied by the java new object reaches the maximum upper limit maxMemory, exceeding 384m or 512M;
  • The second is that there is not enough continuous address space. This situation is generally caused by a large number of memory fragments in the process. The stack information will have more information than the first OOM stack: failed due to fragmentation (required continuous free " << required_bytes << “bytes for a new buffer where largest contiguous free ” << largest_continuous_free_pages << “bytes)”; the detailed code is in art/runtime/gc/allocator/rosalloc.cc. Judging from the error log
    , The OOM of the java heap memory bugly captured belongs to the second type, and there is no continuous space of sufficient size.

Phenomenon

Check the java call stack:
insert image description here
It is found that the Java heap memory is only 4.8M, but a 17M bitmap is to be generated, so OOM is thrown directly. Below android 8.0, the memory occupied by bitmap is in java heap.

Check the device information, all devices below 8.0:
insert image description here

Analysis process

In order to find out which objects are exhausting the java heap memory, or there is a memory leak.

Then, compile the debug package of the app treasure channel of the game, and get the current memory snapshot hrop:
insert image description here
it is found that there are more than 20 17M Bitmaps (28*17m=476M), and the current device is android 12, so the bitmap memory is in the native heap. The oom phenomenon did not occur. If it occurs on devices below android 8.0, these will directly overwhelm the java heap (java heap 512M in the mini world), resulting in oom.

Then, the call found that it was a problem caused by the AnimationDrawable in a certain sdk of Tencent;

insert image description here
In the end, the problem was reported to the partner (Application Technology), and the sdk of Tencent Apex will be hot-updated to fix the problem.

When accessing an external SDK, try to detect the memory, thread, and fd on the demo to avoid uncontrollable risks.

Guess you like

Origin blog.csdn.net/hexingen/article/details/131920860