beast-dev / beast-mcmc

Bayesian Evolutionary Analysis Sampling Trees
http://beast.community
GNU Lesser General Public License v2.1
192 stars 73 forks source link

Memory leak in DefaultTreeModel #1193

Closed rambaut closed 4 months ago

rambaut commented 4 months ago

Repeated constructing DefaultTreeModel uses up all the heap:

    public static void main(String[] argv) throws Importer.ImportException, IOException {

        NewickImporter importer = new NewickImporter("(((D:2.0,C:2.0):1.0,(A:1.0,B:1.0):2.0):1.0,E:4.0);");
        FlexibleTree tree = (FlexibleTree) importer.importTree(null);

        for (int i = 0; i < 100000000; i++) {
            new DefaultTreeModel("treeModel", tree);
        }
    }
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"

Profiler (MB):

image

Not an issue in BEAST as we rarely make more than one. But an issue in the WideExchange test.

rambaut commented 4 months ago

This is the result of all parameters getting put into as static HashMap by Parameter.Abstract:

            FULL_PARAMETER_SET.add(this);

Not sure this needs fixing as we should never create 1000's of treemodels. But the test needs fixing

rambaut commented 4 months ago

Fixed the test by only creating the treemodel once