Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Memory Leak issue with TreeView

cshSep 7 2012 — edited Sep 10 2012
Hi,

I get Memory Leaks in the TreeView, if I open the stage which contains the TreeView several times.

Everytime I open the stage, I clear the TreeView and populate it with new items.

However there are leaks.

I think this is a bug. But maybe my code is wrong and someone could comment on this issue.

See this test case:

i < 10: 5854 KB
i < 100: 35944 KB
i < 200: 64515 KB

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;


public class TestApp3 extends Application {
    public static void main(String[] args) throws Exception {
        launch(args);
    }

    public void start(final Stage stage) throws Exception {

        VBox root = new VBox();

        SubStage subStage = new SubStage();
        for (int i = 0; i < 10; i++) {
            subStage.show();
            subStage.hide();
        }

        System.gc();
        System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + " KB");

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    private class SubStage extends Stage {
        public SubStage() {
            TreeView<String> treeView = new TreeView<String>();
            final TreeItem<String> rootNode = new TreeItem<String>("Root");

            treeView.setRoot(rootNode);

            setOnShowing(new EventHandler<WindowEvent>() {
                @Override
                public void handle(WindowEvent windowEvent) {
                    rootNode.getChildren().clear();
                    rootNode.getChildren().add(new TreeItem<String>("Item"));
                }
            });

            Scene scene = new Scene(treeView);
            setScene(scene);
        }
    }
}
Edited by: csh on 07.09.2012 06:14

Edited by: csh on 07.09.2012 06:14
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2012
Added on Sep 7 2012
7 comments
607 views