Sorry to bug you on this again.
First a question:
Why would function MyDialog( parent )
{
// ...
var foo = new Label( this );
// ...
this.foo = foo;
// ...
}
be dangerous?
My understanding is that the Control (Label) Javascript proxy will delete the Label when it is garbage collected. The label is referenced by a local variable in the method, and surely the local variables are not garbage collected before we exit of the scope (or at lease before they are not referenceable anymore)? I am asking this because it is often boring and error prone to add 'this' everywhere (or not quite right everywhere) and would be simpler if we could just add the control to the sizer before its variable can be out of scope.
Then, after making the required changes on one script and working on another, I found this issue pretty annoying, especially if you do some dynamic controls or control tables. It is easy to forget, and impossible to test. I have looked at SpideerMonkey and it is true that the GC and its documentation is not very clear. But considering that the only (or at least usual and correct) way to add a control is via the Javascript proxy of a Sizer, via the add/remove, could the Sizer proxy not have a private field to whish it would add/remove controls when they are added/removed from the Sizer ? Naturally this only works if the control proxy keeps track of the Sizer proxy and does not generate a new one when the property is referenced. This may not cover all the cases, especially not if Javascript and native code is ever mixed, but would avoid maintaining a parallel hierarchy manually.
Alternatively I could make sub classes of the controls and Sizer to provide this functionality, but I am not sure this would work as the PJSR is pretty picky on the class herarchy of controls. Besides, I am lazy.
-- bitli