

visualvm_xyz/bin run the shell script './visualvm' (or visualvm.exe on windows). (But Thermostat and MAT also work.) Configure VisualVM To help you with this process: I recommend to try using a tool like VisualVM. You could read all of your code and try to understand where the leak occurs.

If you got this far then you'll have to roll up your sleeves and do some manual labor. 2) Manually Disable & Enable Parts of Your Code and Observe Memory Usage of Your JVM Using a JVM Tool Like VisualVM. If you're in this place, you may want to try step 2. Or sometimes file opening/closures are nested so deeply that eclipse won't detect them. Especially when working with legacy (pre 1.5) code, you'll likely run into leaks because those were written before 'closable' was implemented. However, even with fancy Eclipse hocus pocus, not all file closures and leaks are detected. Go to your project settings and enable them as demonstrated: However, the leak-detection isn't always enabled in Eclipse projects. To be more precise, anything that implements closable (since 1.5 - e.g outputstream since 1.5) will throw a warning at you if its reference is destroyed but the object is not closed. 1) Quick Fix: Eclipse Memory Leak warning/errors.įor code with JDK 1.5+ compliance, Eclipse will throw warnings and errors at you for obvious cases of leaks. If that fails then you'll have to go down the long road.ġ) Quick fix: Eclipse Memory Leak Warnings (catches some leaks)Ģ) Manually disable & enable parts of your code and observe memory usage of your JVM using a JVM tool like VisualVM (or Jconsole, or Thermostat). Inner classes that reference outer classes can leak.Map.put(new MemLeak(" key" ), " value" ) Hash maps keeping references alive if equals() and hashcode() are not implemented, e.g.Ever increasing Old-Generation memory usage in your JVMĪ memory leak in Java (who would've thought?) can occur if you forget to close a resource, or a reference to an object is not released.Works fine with small data sets, severe performance issues with large data sets.Works fast at first, but slows over time. While, in general, the approach described in this article is IDE & OS independent, I used Linux and Eclipse in the screenshots & instructions. When fixing memory leaks, if someone were to ask me: "If you knew back then what you know now, what would you tell yourself?" Well, I would say. Do you have a Java application that runs fine at first but slows down after a while, or it runs fine for a small number of files but performance degrades for a large number of files? Maybe you have a memory leak.
