Can large HashMap lead to out of memory exception in Android?

815 views Asked by At

I am maintaining a Map of around ~200 items. Can it lead to out of memory exception? Is it a good practice to store big data 200+ or 500+ items in a Map to avoid loading from network or Sqlite?

Also below is my app Heap Size, is it normal or taking much RAM?

enter image description here

1

There are 1 answers

0
angryd On

If you are afraid of OOM by useing HashMap, you can try SparseArray or ArrayMap.

SparseArray:

It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

ArrayMap:

ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional HashMap