Steps to reproduce: 1. Open the forEachTestPlan.jmx demo plan 2. Run it few times 3. Close the test plan Result: If you take a heap dump and analyze it in a tool (jhat eg.) you can see there are HttpSampleResult objects dangling. I've analyzed the situation and there are at least 2 causes: 1. nodesToGui map in the GuiPackage class - this needs to be properly cleaned up once the test plan is closed 2. also a ViewResultsFullVisualizer instance containing HttpSampleResults objects is kept alive by the reference from the ResultCollector.listener field I tried to come up with an easy fix but especially the cause nr.2 is tightly connected to the jmeter architecture so it'd be better if someone with deeper understanding of it would take a look at this issue
Created attachment 21231 [details] Should fix memory leak when closing test plans Plz, review the patch whether it doesn't affect other functionality
Thanks very much - the patch looks good. {I like the way you moved the clearTestPlan() call into GuiPackage. Neat.)
Unit testing shows a problem with the AbstractListener patch - clone() causes an NPE. However, that is easy to fix, just use: clone.listener=this.listener; instead of: clone.setListener(getVisualizer()); [clone() should probably have been coded that way originally.] I'll try some more tests and apply the patch if all goes well.
Seems to work OK, so added to SVN in r601473. Had to make one more change, as the listener may not be present: protected final Visualizer getVisualizer() { if (listener == null){ // e.g. in non-GUI mode return null; } return (Visualizer)listener.get();
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2052