On Jul 22, 12:22 am, jay <[email protected]> wrote:
> OK, I think this now gets into how the GWT compiler generates
> JavaScript from the Java sources... Say I have something like this:
>
> class Foo extends HorizontalPanel {
> public Foo() {
> final Button b1 = new Button( "OK" );
> b1.addClickHandler( new ClickHandler() {
> public void onClick(ClickEvent event) {
> handleButton( b1 );
> }
> } );
> add( b1 );
>
> // Add some other buttons in a similar
> // pattern as above
> }
>
> private void handleButton( Button b ) {
> // do stuff here
> }
>
> }
>
> Now, in Java, the anonymous ClickHandler inner class will have a
> reference to the outer class. I assume that the generated JavaScript
> also must have a reference, otherwise there'd be no way for it to call
> the handleButton() method.
>
> In this case, the handler *does* have a reference to the widget.
>
> So...my question now is: Will this reference prevent the GC from
> taking care of the Foo, Button, and handler instances when Foo goes
> out of scope? Does it perhaps vary by browser? (Maybe....IE can't
> break such cycles, but FF can?)
Really, I don't know. I'd just rewrite the code to remove the
reference, just in case:
b1.addClickHandler( new ClickHandler() {
public void onClick(ClickEvent event) {
handleButton( (Button) event.getSource() );
}
} );
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.