I am developing in NDK
. It hangs in Galaxy S3
. For testing I put android:largeheap = "true"
in Manifest
. Then there was no hanging issue.
Is it a good practice to use largeHeap="true"
?
Is there any chance that Google rejects my build due to this tag and
how can I prevent my app from hanging without using largeheap="true"
?
Actually android:largeHeap is the instrument for increasing your allocated memory to app.
Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
android:supportsRtl. Declares whether your application is willing to support right-to-left (RTL) layouts. If set to true and targetSdkVersion is set to 17 or higher, various RTL APIs will be activated and used by the system so your app can display RTL layouts.
No, if you need it it is not a bad pactise because it is there for it.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With