Resources leaking in OutlineView

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Resources leaking in OutlineView

Dmitry Avtonomov
​Hi all,
I'm trying to automatically expand my OutlineView right after creation​:

// create the components
ExplorerManager em = new ExplorerManager();
OutlineView ov = new OutlineView();
Node root = new ...
em.setRootContext(root);

// run node expansion
Runnable runNodeExpansion = new Runnable() {
    @Override
    public void run() {
        Node toExpand = root;
        Node prevNode = toExpand;
        boolean foundChildren, nodesEqual;
        do {
            //ov.expandNode(toExpand);
            Node[] nodes = toExpand.getChildren().getNodes(true);
            foundChildren = false;
            nodesEqual = false;
            if (nodes != null && nodes.length > 0) {
                toExpand = nodes[0];
                foundChildren = true;
                nodesEqual = toExpand.equals(prevNode);
                prevNode = toExpand;
            }

        } while (foundChildren && !nodesEqual);
        ov.expandNode(toExpand);
    }
};
SwingUtilities.invokeLater(runNodeExpansion);


If I don't run the expansion code - everything works. As soon as the expansion code is run within the constructor of my top component the expansion itself works - it drills down along the first child nodes till it finds a node with no children and expands that path. But any navigation around the tree (e.g. pressing arrow keys on keyboard) triggers uncontrolled CPU usage and memory usage grows quickly to gigabytes. It seems like calling Node#getChildren()#getNodes() is causing some problems, but I'm not sure. Is there something obviously wrong with the above code?

Regards,
Dmitry Avtonomov


Loading...