How to measure memory usage?
843798Aug 1 2001 — edited Aug 2 2001Hi all!
Is there any more sophisticated way of getting the memory requirements of objects at run-time?
Currently I'm using Runtime.totalMemory()-Runtime.freeMemory() to estimate the memory usage before and after loading the object in question. The difference should be the memory used by the object. I also call upon Runtime.gc() to make sure that the garbage collector is run before each of the measurements. Unfortunately Java doesn't guarantee that the garbage collector is really run and that all unused objects are removed from memory even if it is run.
Although this method gives you a rough indication of memory usage (at least for very big objets), I would like to have something more precise (and repeatable). Using the method above on two big objects created in different order leads to different results.
mneumi