posted 9 years ago
Thanks, Campbell! The explanation is very make sense and similar as I thought.
also one more informaiton for the test, the jvm paramter is "-Xmx256m -Xms8m"
if I do nothing, and only print hello world, I can see the memory usage is around 10M
so if only tetsing creating 1M array, I get the memory usage arund 14M , which means the new array used additional 4M , which make sense, since int as 32 bit and 4 bytes, * 1M = 4M
For arrayList , as you described, I assume when I add the data less the 600K, (less than loading factor 0.75) it should be similar usage as array, around 4M , and when I insert 1M data, list will double the size , and it may use 8M for 2M int array.
insert 1M data for arraylist, the memory usage is 36M , which meeans the arraylist could use 36M -10M = 26 M
insert 0.5M data in arraylist, the memory usage is 24.6M (around 25M), which means 15M = 25M - 10M
For hashmap, I did same thing for 1M data, and 0.5M
1M data in hashmap, the memory usage is 119M . it means double hashmap (for 2m) could use 119 - 10 = 109 M
0.5M data in hashmap , the memory usage is 72M, it means the hashmap could use 72M - 10 M = 62M
Looks like the array usage is match what I think, but arraylist, and hashmap use more than I expected. Not sure if jvm also need to allocate other memory for the arraylist and hashmap memory?
Thanks