Is using largeheap in Android manifest a good practice?

前端 未结 2 517
不思量自难忘°
不思量自难忘° 2020-12-17 22:37

I am developing in NDK. It hangs in Galaxy S3. For testing I put android:largeheap = \"true\" in Manifest. Then there was

相关标签:
2条回答
  • 2020-12-17 22:47

    Short Answer

    No, if you need it it is not a bad pactise because it is there for it.

    Long Answer

    Official doc states

    Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application.
    It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use this option consistently or they will have unpredictable results.
    Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.

    Some developers uses it to avoid OOM excepetion, so if you are using it just to avoid some OOM it is a very very bad pactice.

    Never request a large heap simply because you've run out of memory and you need a quick fix. You should use it only when you know exactly where all your memory is being allocated and why it must be retained


    If you actually need more space it's ok to use it, you can use getMemoryClass() to check the heap and getLargeMemoryClass() large heap.

    But if you can avoid using the largeHeap it would be the best way to go, as the official documentation continues:

    Yet, even when you're confident your app can justify the large heap, you should avoid requesting it to whatever extent possible. Using the extra memory will increasingly be to the detriment of the overall user experience because garbage collection will take longer and system performance may be slower when task switching or performing other common operations.
    Additionally, the large heap size is not the same on all devices and may be exactly the same as the regular heap size. So even if you do request the large heap size, you should call getMemoryClass() to check the regular heap size and strive to always stay below that limit.

    I also suggest you to have a look here Managing Your App's Memory

    0 讨论(0)
  • 2020-12-17 23:11

    Personally I would say it doesn't really fall into the category of either 'good/bad practice' when used correctly.

    According to the docs:

    Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.

    If you have done everything in your power to reduce memory usage, and still require it, then it isn't a bad thing to use it.

    If your app is hanging, you will need to directly address that - the largeHeap isn't a magic wand that will make problems go away for all devices. This point is made clear from the following extract of the Android Training docs:

    [The] ability to request a large heap is intended only for a small set of apps that can justify the need to consume more RAM (such as a large photo editing app). Never request a large heap simply because you've run out of memory and you need a quick fix—you should use it only when you know exactly where all your memory is being allocated and why it must be retained. - (source)

    I should also add that Google will not reject your app for using it.

    0 讨论(0)
提交回复
热议问题