Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    onDetach() doesn't get called

    Hi There,

    It seems like when I remove a widget from a canvas, onDetach() doesn't get called. This is problematic because I want to clean up the state when the widget is removed from the page.

    Also, How come I don't receive any error (exception) message when running in web mode when something goes wrong such as a null pointer exception? Was it being consumed and suppressed somewhere?

    Many thanks,
    Kevin

    #2
    For debugging errors in a deployed application (which would be JavaScript errors), use Firebug and the SmartClient Developer Console.

    About onDetach() - under what specific circumstances are you seeing it not fire (eg, is this purely SmartClient widgets or a possible interop issue) and what are you trying to clean up?

    Comment


      #3
      Originally posted by Isomorphic
      About onDetach() - under what specific circumstances are you seeing it not fire (eg, is this purely SmartClient widgets or a possible interop issue) and what are you trying to clean up?
      It's interop issue where we include and then remove a GWT widget from a smartgwt canvas. Here is a sample code just to illustrate this issue:

      Code:
          final VStack layout = new VStack(10);
          layout.setWidth100();
          layout.setHeight100();    
          
          final Canvas hello = new WidgetCanvas(new com.google.gwt.user.client.ui.Label("Hello"));
          final Canvas remove = new IButton("Remove");
          remove.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
              layout.removeChild(hello);   
              remove.disable();
            }
          });
          
          layout.addMember(hello);
          layout.addMember(remove);
      
          layout.draw();
      When "Hello" is removed from the layout, onDetach should be called which in this case it does not. If we look at GWT's implementation of onDetach() in Widget class, it recursively passing the call to its children, remove the event listener, and set attached flag to false. To quote from GWT's documentation of onDetach():
      Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects.
      In hosted mode, when you refresh the page after removing "hello" canvas, you will get this exception:

      Code:
      [ERROR] Uncaught exception escaped
      java.lang.AssertionError: A widget in the detach list was found not attached to the document. The is likely caused by wrapping an existing element and removing it from the document without calling RootPanel.detachNow().
      	at com.google.gwt.user.client.ui.RootPanel.detachWidgets(RootPanel.java:200)
      	at com.google.gwt.user.client.ui.RootPanel$1.onWindowClosed(RootPanel.java:221)
      	at com.google.gwt.user.client.Window.fireClosedImpl(Window.java:465)
      	at com.google.gwt.user.client.Window.fireClosedAndCatch(Window.java:456)
      	at com.google.gwt.user.client.Window.onClosed(Window.java:430)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:585)
      	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
      	at com.google.gwt.dev.shell.moz.MethodDispatch.invoke(MethodDispatch.java:80)
      	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
      	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1428)
      	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
      	at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
      	at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
      	at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)
      Many thanks.

      Comment


        #4
        Any words on this issue? What I was expecting that removing a member from the layout, onDetached should be invoked to avoid memory leak.

        Comment


          #5
          Any news? I have the exactly same problem, and as well seems that this behaviour cause problems in IE.

          Comment


            #6
            Hi,

            You can call widget.destroy(). Something like this:

            hello.destroy();
            layout.removeChild(hello);
            Last edited by la123; 18 May 2009, 22:54.

            Comment


              #7
              Uhm, i have the problem on a MapWidget (GoogleMaps GWT Library) and only when the mapWidget is displayed in a TabSet.
              Actually only when the user at least "see" the mapWidget (no if a tab with a mapWidget is created but never selected).

              MapWidget has no destroy() or hide() and calling those methods on his parent don't work..
              Last edited by bebo; 19 May 2009, 04:08.

              Comment

              Working...
              X