I want to calculate the memory usage of two HashMaps in Java and I did these two methods.
1) I use the visualVM and I got following result.
Is it just the size of the Hashmap's pointer not the real amount of memory usage with this Hashmap?
Because, it just used ''67283648'' bytes.
2) I run the following code which fill two HashMaps and I got ''576132056'' bytes as a result.
Runtime runtime = Runtime.getRuntime();
long memory = runtime.totalMemory()- runtime.freeMemory();
HashMap<String, TypePosting> typeInvIndex=qpu.loadInvTypeIndex();
HashMap<Integer,String> map=qpu.loadMapTypeEntityId();
long memory1 = runtime.totalMemory()- runtime.freeMemory();
System.out.println(memory1- memory);
I just asked this question to be sure that I the second result is the correct value of space usage of these two Hashmaps correctly. Am I correct?