0

I have an application that creates a hashMap of size 1300. The value in the hash map is an object called employee Data and key is just a string - EmpName. The object has a list. Rest other fields in the object are either String or double. The list size in the object varies between 4 to 5000. I want to do a rough calculation of the memory consumption. Could you please help me with it? I also want to know how GC will free this memory.

I did some calculation: The other fields will consume around 512 bytes each I am not sure how to calculate the consumption of the list. The list contains all double value. Also I am not how much memory of the object will increase with different size of the list and how will it contribute the overall memory consumption.

codemaster001
  • 183
  • 1
  • 16

1 Answers1

0

This could be the answer you're looking for.

Memory usage for a specific list of object

The objects will be Garbage-Collected once the list no longer references to the objects; i.e; when the object is removed from the list.

  • How can I calculate the memory foot print of a list? – codemaster001 Feb 18 '20 at 01:10
  • https://stackoverflow.com/questions/4802651/memory-usage-for-a-specific-list-of-object – Swapnil Ingle Feb 18 '20 at 01:12
  • Is there a way we can theoretically calculate this? – codemaster001 Feb 18 '20 at 01:28
  • Yes ... if you understand enough about the way that objects are represented in the heap AND the internal details of HashMap, the List class you are using, your custom classes etcetera. But the analysis is tedious. For collections, the size may depend on the past history of the collection object. – Stephen C Feb 18 '20 at 03:12