magallanes magallanes - 5 months ago 29
Java Question

What is the memory size of an ArrayList in Java

I have an

and I wish to know how much memory it is using.

is variant so, it is not as easy as multiply the number of elements in the array per the size of an object.


You can use something like Runtime.getRuntime().totalMemory() and its counterpart Runtime.getRuntime().freeMemory() to get an educated guess, but that doesn't account for objects that are GC'ed between calls.