Possible Duplicate:
In Java, what is the best way to determine the size of an object?
Suppose you have a data structure which allows you to add data to it, say a list:
List<KeyValuePair>
As client of the system actually adds content ... at some point, JVM will run out of memory, it is only a question of when this happens. It would be nice to periodically save the object that contains this list to disk and gc
the rest.
Using Java, is it possible to estimate how much memory an object is taking now?