Android Question Increasing Heap Memory

DT1111

Member
Licensed User
Longtime User
Are there any known trade-offs when the heap memory is increased? Does it have impact on computational or overall app speed, etc? Just curious.

B4X:
SetApplicationAttribute(android:largeHeap,"true")

Thanks.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
I don't think there's any effect on app speed, though this is something you could easily test to your own satisfaction. As for other trade offs, there's a chance an app with a largeHeap will be selected earlier by the OS for killing if the OS needs the RAM for something else.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Are there any known trade-offs when the heap memory is increased? Does it have impact on computational or overall app speed, etc? Just curious.

B4X:
SetApplicationAttribute(android:largeHeap,"true")

Thanks.
Theoretically, there's an impact on performance. As Google says:
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.
 
Upvote 0

DT1111

Member
Licensed User
Longtime User
Thanks both for your inputs.


Is it possible to have a conditional activating of heap memory in the manifest.


When my app which is “bitmap intensive” runs on a large screen e.g FHD screen via an Android box, it will crash with an out of memory exception. That has been solved by activating the heap memory ie I have no choice even if the heap memory has some detrimental effect on the system.


But when the app runs on little tablets eg 10", the out of memory exception never occurs. So I think it is better to deactivate the heap memory.


In other words


If run on large screen then
activate heap memory
else
deactivate heap memory


Is that possible in the manifest file?


Thanks.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
You have to create a configuration file. First, you replace the boolean value by a variable in your manifest:
SetApplicationAttribute(android:largeHeap,"@bool/largeheap")
Then you create a config file (its name doesn't matter) that contains true or false and you put it in the folder corresponding to the targeted screen. For example in objects/res/drawable-xhdpi or objects/res/layout-xlarge (see this doc for further details).
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="largeheap">true</bool>
</resources>
 
Upvote 0
Top