Friday, May 29, 2009

Poor Man's Java memory profiler

Here is an example of do-it-yourself memory profiling e.g. showing used heap memory over the life of a program run. I compared it with results from YourKit to convince myself it's ok.

The concept:
  • Launch a separate thread that collects used memory stats
  • add a shutdown hook to output the stats