1

Operating environment:
Device information: HUAWEI MatePad Pro
Machine model: MRR-W29
System version: HarmonyOS 2.0.0

Problem: Running our app, using AndroidStudio, it crashed before 1GB of memory was available.

System out of memory graph

Crash log information:

Could not allocate memory: System out of memory!
Trying to allocate: 25310B with 16 alignment. MemoryLabel: DynamicArray
Allocation happened at: Line:75 in 

Memory overview
[ ALLOC_DEFAULT ] used: 600916429B | peak: 944389110B | reserved: 607460466B 
[ ALLOC_TEMP_JOB ] used: 0B | peak: 0B | reserved: 3145728B 
[ ALLOC_TEMP_BACKGROUND_JOB ] used: 0B | peak: 0B | reserved: 1048576B 
[ ALLOC_GAMEOBJECT ] used: 5812624B | peak: 5863041B | reserved: 6525010B 
[ ALLOC_GFX ] used: 23019376B | peak: 24012532B | reserved: 23072348B 
[ ALLOC_TEMP_THREAD ] used: 33012B | peak: 0B | reserved: 3047424B 

Androidmanifest.xml Application: android:largeHeap="true" How does HarmonyOS system break through the App memory limit, or have other solutions, as well as the idea of solving the problem? Thank you in advance for any guidance or assistance.

Iogui
  • 1,526
  • 1
  • 17
  • 28
严学文
  • 11
  • 2

1 Answers1

0

On Android memory allocation is not as simple as "there is a memory so app can take it all". A lot of algorithms are evaluating your app behavior and if it takes a lot of memory without good reason, or it's allocating memory crazy fast - Out of memory exceptions tends to happen. It's not really deterministic from the app perspective as far as i know. Memory allocation from the system side is basically implementation detail, so it may vary between providers. There is no standard behavior how to treat apps here (as far as i know, i might be wrong here).

Using android:largeHeap="true" is basically sign that you should look at your app memory usage. Are you doing something that really requires more than 1GB of memory? It seems super fishy. Even on desktop app it would raise a lot of flags

Jakoss
  • 4,647
  • 2
  • 26
  • 40
  • Thank you for your reply. We are making 3D home decoration design software, we really need a few G of memory, otherwise our scheme scene will not open 。What to solve train of thought excuse me? – 严学文 Aug 27 '21 at 01:36
  • I would love to help you, but there is nothing (as far as i know) other than `android:largeHeap` flag that you can do to "ask" system for more memory allowance. Honestly the only way to fight OOM is to optimize memory usage. You can search for some memory leaks, use some caching on sd card, but there is nothing you can do system wide here. What you can do is check if you have memory or you should stop allocations: https://developer.android.com/topic/performance/memory#CheckHowMuchMemory – Jakoss Aug 27 '21 at 07:14
  • Ok, I will check the memory information according to the way you provided. If I can't find a way, I can only optimize the memory honestly – 严学文 Aug 27 '21 at 13:44