[antlr-interest] On trees and JavaBeans, part 2: tree creation

Scott Stanchfield scott at javadude.com
Thu Apr 21 17:58:13 PDT 2005


I just downloaded the sample (http://javadude.com/misc/treesample.zip) and
extracted it again. You ARE looking at the BAD example. GoodExample is:


public class GoodExample {
	public static void main(String[] args) {
		Ftp ftp = new Ftp(); // a UI
		
		JFrame f = new JFrame();
		f.getContentPane().add(new JScrollPane(new JTree(new
ComponentTreeModel(ftp))));
		f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		f.pack();
		f.setVisible(true);
	}
}

Now look at ComponentTreeModel.java.

See any TreeNodes? (If you do, you're seeing things that aren't there.)


They're not necessary, and getting rid of them saves lots of memory and GC
time over time, whether it's on a server, or in eclipse.

Even for a single-run app, it can mean the difference between running out of
memory. Many people avoid DOM because it uses too much memory. What we we
added an extra node on top of each DOM node to parse it? Kaboom.

-- Scott






More information about the antlr-interest mailing list