Strong opinions, weakly held

Finding a memory leak

I have some Java code that leaks memory and causes Tomcat to die with an out of memory error once every couple of days. After finding a way to reproduce the problem reliably in a JUnit test outside Tomcat and exhausting the obvious means that I know about to find such problems, I’ve jumped into the world of profilers. I’ve always felt like profilers are a tool that real developers should know how to use, but I’ve never had to use one. (I also feel that way about debuggers. I debugged programs for years with print statements until I learned how to use a debugger — now I could never go back.)

Anyway, I’m trying out two profilers right now, JProfiler, which provides a 10 day evaluation license and YourKit, which provides a 15 day evaluation. The first thing I figured out is that there’s more to finding memory leaks than running your code in the profiler, or at least there is in this case.

My goal is to find and solve the problem before either evaluation license expires, and to decide whether I need to buy either of these products. I’ll post about my progress here, and welcome any comments with further information on hunting down and killing memory leaks in Java programs.


  1. I really like YourKit. Its really easy to use, and you can install it on a production system but only enable it when you want to gather data, so it doesn’t hurt performance when its not enabled.

    Take a look at this tomcat bug:


    It causes a pretty big memory leak, and it seems to bite a lot of people.

  2. I’m not sure if you’re doing this on a mac- but in the off chance that you are, Shark (a free profiler from Apple) can now profile java code from what I understand.

  3. Good luck. I wrote a “print preview” feature in Swing that generated a jpeg preview of documents. For some reason the VM would never free the memory used for the graphics, no matter what I did. I tried several profilers including YourKit before giving up in frustration.

    If you DO solve it, a thorough explanation would be most appreciated.

Leave a Reply

Your email address will not be published.


© 2019 rc3.org

Theme by Anders NorenUp ↑