1

I am currently working on reducing the RAM memory consumption of an app because the app throw a out-memory error.

I don't know if the number of methods in an activity impacts in memory consumption but, if my idea is correct, how can I improve this?, Using more static methods?

Or what other recommendations can you make?, I made memory profiles, dependency injection (manually, nothing from Hilt Dagger or other library), reduction of bitmaps type variables, change to MVVM design pattern, change of graphic images to vectors.

Any comment can help me, thanks

1 Answers1

0

if your application uses a lot of images with high resolution without scaling them or using a 'plugin' to load them like Glide, they will cause a lot of problems staying in memory together.

there's a solution that's not the prettiest solution of them all, but would work to make your application live during the memory surge is to unlock the largeHeap attribute in android manifest, it should make your app consume the memory it wants until you're finished with your bitmaps letting the garbage collector claim their memory again.

<application
        ...
        android:largeHeap="true"
        >
</application>

anyway it's not the prettiest solution as I said incase if your application suffers from memory-leak problems that you keep unnecessary data referenced in memory for indefinite amount of time preventing GC from collecting them, that way your application memory consumption will keep raising until the OS can't tolerate it.

here's a good answer to when you should use largeHeap or shouldn't and how would you deal with out of memory exception may it help if you haven't seen it before.

Omar Shawky
  • 1,242
  • 1
  • 12
  • 25
  • Thank you very much for your help, unfortunately I cannot use the largeHeap tip, because the development I have to do it for smartphones that on average do not have more than 1 gb of RAM, I will check if I can optimize with Glade Greetings – Juan Pablo Leiva Burgos Sep 21 '21 at 17:00