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?)


Thanks for the help here! It is truly appreciated as I try to
understand "gotchas" that may lead to memory leaks...

jay


On Jul 21, 6:14 am, Thomas Broyer <t.bro...@gmail.com> wrote:
> On 20 juil, 01:32, jay <jay.gin...@gmail.com> wrote:
>
> > Ah, so that's good for handlers of *DOM* events [e.g., using
> > addDomHandler()]. For "logical" events [those added via addHandler()],
> > however, it seems like you may still need to manuallyremove
> > listeners.
>
> > Is that correct?
>
> As long as thehandlerdon't have a reference on the widget (or
> whichever object you attached thehandler), no. If the widget is
> garbage collected, its internal HandlerManger will also be, and 
> yourhandlertoo (unless you have another reference to it).
> Exception: if you keep a reference to the HandlerRegistration, you're
> also responsible for callingremove() (but why would you keep a
> HandlerRegistration around otherwise?)

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to