Hi Andy,
> showMain: function()
> {
> ... <snip> ...
>
> table = new qx.ui.table.Table(model);
>
> layout = new qx.ui.layout.HBox(0);
> layout.setAlignY("middle");
> hbox = new qx.ui.container.Composite(layout);
> var txt1, txt2;
> txt1 = new qx.ui.form.TextField();
> hbox.add(txt1);
> txt2 = new qx.ui.form.TextField();
> hbox.add(txt2);
>
> btn = new qx.ui.form.Button("Add");
> hbox.add(btn);
>
> var tc = table.getTableColumnModel();
> tc.addListener("widthChanged", function(e) {
> txt1.setWidth(e.newWidth);
> txt2.setWidth(e.newWidth);
> }, this);
> ... etc ...
> }
>
> Now as I understand it, the inner function has access to the outer
> functions variables even after showMain exists. But, if I ever do
> something like:
>
> this.getRoot().removeAll();
>
> to clear everything so I can draw a totally different screen, will txt1
> and txt2 ever get freed? Because there will always be a reference to
> them, right?
>
Generally, qooxdoo is quite good in cleaning up, so I don't think you
have to worry much about leaks, especially if you stick to API methods
to dispose objects.
More particularly concerning event listeners, my understanding is that
"incoming" listener relations are automatically removed with an object.
In your case, if you destroy tc, the TableColumnModel, all listeners
listening on its events will be removed cleanly and automatically.
"Outgoing" listeners will not be removed automatically, ie. when you
destroy the object containing the showMain() method, the listener will
be left dangling on the TabelColumnModel (provided it is independent and
continues its life cycle). The same should be true if you destroy
objects that are referenced inside the listener, like txt1 and txt2 in
your case. But since you are trying to wipe out all objects this
shouldn't be an issue in your case.
> My basic goal is to have a table that show's data, and under it have a
> series of textFields and an "insert new" button. It would be cool if
> the textFields had the same width as the table columns, then it would
> look pretty. I know the code above is not "exactly correct". (If
> anyone had a simpler method of doing this I'd be interested)
I think this is something you probably shouldn't do by hand. Layout
managers are there to do these kind of things. If you put your table and
the text fields in a Grid or VBox layout, given the right flex
properties, you should have the widgets' widths automatically aligned.
> But I'm
> still interested in the closure question. Is it dangerous/bad for inner
> functions to use UI objects of outer functions?
>
No, it's a common practice. If you want to know more about memory
management in qooxdoo, see
http://qooxdoo.org/documentation/0.8/memory_management.
HTH,
T.
> Thanks,
>
> -Andy
>
> ------------------------------------------------------------------------------
> _______________________________________________
> qooxdoo-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
>
------------------------------------------------------------------------------
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel