Java Memory Overhead

Posted by flamealpha on Stack Overflow See other posts from Stack Overflow or by flamealpha
Published on 2010-04-27T12:50:01Z Indexed on 2010/04/27 12:53 UTC
Read the original article Hit count: 404

Filed under:
|
|
|
|

Hello, I would like to ask about Memory Overhead in java, I have a large ArrayList (61,770 items), and trying to calculate the amount of memory taken by each item (counting the object and its ArrayList entry), by profiling the app i get that after all the data is loaded, the heap takes ~ 25Mb. when the ArrayList has only 2 items the heap takes ~1Mb , so roughly:

(24*1024*1024)/61,768 = 407 bytes.

however, when i count the fields of the each object, i get 148 bytes(not including the ArrayList, and assuming int=4,float=4,reference=4), I am curious to know where did all of those extra bytes came from...

i can guess that since the objects I store in the ArrayList are implementing an interface, they store extra values, maybe the VM stores a 4byte function pointer for each implemented method? the interface they implement have 20 functions so thats 80 more bytes, totaling 228 bytes, still not close to the 400 bytes measured.

any help would be appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about memory