Poor Man’s Profiling

Some time back I wrote about how OptimizeIt was useful in profiling our application. If you can’t afford OptimizeIt Java provides you an alternative poor man’s profiling tool in the Runtime class. The Runtime class allows you get the total heap size and the amount of available memory. Using these methods you can estimate how much memory you application is consuming with some simple math:

Runtime rt = Runtime.getRuntime();
long using = (rt.totalMemory() - rt.freeMemory()) / 1024;