Monday, June 13, 2011

"Find X biggest object by retained size" function in jVisualVM help find memory leak in your program

After adding the component to interface RF Code Zone Manager with a custom InterMapper SNMP probe, I went about load testing it to ensure the stability of the solution. I have created a map of many many probe and set them to poll at 1 second interval.

During the load testing, I observed this steady growth in memory:

Not a good sign.

Good news is the jVisualVM has made finding the memory leak so easy!  I recall in the old days memory leak hunting use to be a pain without enterpricy tools such as YourKit.
I don't know when this was added to jVisualVM, but this function, "Find X biggest object by retained size", is tremendously helpful in finding the root cause of the memory leak!

Why is this function helpful? To understand how this function will help determine the root cause from memory leak, refer to this article, "Shallow and retained sizes", by the folks at YourKit.
Now just examine the classes with the largest retained size, and they are probably the classes giving you your memory leak problem!