import org.gnu.gtk.DataColumn;
import org.gnu.gtk.DataColumnString;
import org.gnu.gtk.DataColumnObject;
import org.gnu.gtk.TreeIter;
import org.gnu.gtk.TreeStore;


public class TreeStoreLeak
{

    static 
    {
	System.loadLibrary("glibjava-0.2");
	System.loadLibrary("glibjni-0.2");
    }

    public static void main (String[] args)
    {
	Leaker l = new Leaker ();
	l.startLeaking ();
	System.exit (0);
    }


    protected static class Leaker
    {

	private DataColumn[] columns;
	private TreeStore store;

	public void startLeaking ()
	{
	    this.columns = new DataColumn[] { new DataColumnString(), new DataColumnObject() };
	    this.store = new TreeStore (columns);
	    while (true)
		{
		    MyObject myObj = new MyObject();
		    String foo = "123123qweqwe123123qweqwe";
		    TreeIter iter = this.store.appendRow (null);
		    this.store.setValue (iter, (DataColumnString) this.columns[0], foo);
		    this.store.setValue (iter, (DataColumnObject) this.columns[1], myObj);

		    this.store.clear ();
		    System.gc();
		    Thread.yield();
		}
	}
    }

    static class MyObject
    {
	private Object[] leak = new Object[100];
	
	protected void finalize ()
	{
	    System.err.println(this + " has been collected!");
	}
    }

}
