In a few cases, I've found that the Widget I'm working with isn't
getting events as I expected. Fixing this entails something like this:
  class MyWidget extends Widget {
    . . .
     protected void onAttach() {
      super.onAttach();
      DOM.setEventListener( getElement(), this );
     }

Can someone tell me if I'm at risk of a memory leak by doing this?

(For completeness, one place I had to do this was in a class I
created, ResizablePanel, which captures mouse events to allow the user
to click & drag an edge of the panel to resize it. [You'd never guess
that functionality from the class name, huh? :-) I don't remember now
where the mouse events were going, but the only way I could figure out
for this class to get them was to set itself as the event listener...]

Thanks,

jay

On Oct 7, 7:29 am, Thomas Broyer <[EMAIL PROTECTED]> wrote:
> On 7 oct, 15:38, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > Thanks.
>
> > Is there recommandation to use DOM ? how must i use
> > DOM.seteventlistener ?
>
> You have to call DOM.setEventListener(elt, null) whenever "elt" is
> detached from the document (that's what Widget.onDetach does) or at
> least at "unload" time (RootPanels are detached at on unload, and thus
> detach their children in cascade; same goes for widgets created with
> their static wrap() method, as they automatically register themselves
> for RootPanel.detachOnWindowClose).
>
> Actually, you'd rather create a Widget and follow the static
> wrap(Element) pattern found on other widgets (Button, TextBox, etc.)
> than directly play with DOM.setEventListener. Or just be careful to
> reset event listeners to "null" before "unload" for each element
> you've attached a listener to.
>
> > Is it possible to have memory leak when using DOM.getElementAttribute
> > or DOM.getParent for example ?
>
> I don't think so. Actually, memory leaks are mostly caused by DOM
> elements referencing javascript objects referencing back the DOM
> element (which is easily done when attaching events in "pure
> JavaScript"). You shouldn't suffer from memory leaks with GWT except
> if you start playing with DOM.setEventListener and/or JSNI.
>
> That being said, I'm not a JavaScript expert wrt memory leaks, so
> you'd better check before taking my word for it :-P
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to