Revision: 8200
Author: [email protected]
Date: Thu May 20 05:21:35 2010
Log: Fixes a memory leak on IE with the cross-site fragment loading strategy.
Now the callbacks on script tags are removed when they are invoked.

Review at http://gwt-code-reviews.appspot.com/544801

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8200

Modified:
/trunk/user/src/com/google/gwt/core/client/impl/CrossSiteLoadingStrategy.java

=======================================
--- /trunk/user/src/com/google/gwt/core/client/impl/CrossSiteLoadingStrategy.java Thu Apr 1 08:51:36 2010 +++ /trunk/user/src/com/google/gwt/core/client/impl/CrossSiteLoadingStrategy.java Thu May 20 05:21:35 2010
@@ -59,6 +59,18 @@
   private static RuntimeException LoadTerminated = new RuntimeException(
       "Code download terminated");

+  /**
+   * Clear callbacks on script objects. This is important on IE 6 and 7 to
+ * prevent a memory leak. If the callbacks aren't cleared, there is a cyclical + * chain of references between the script tag and the function callback, and
+   * IE 6/7 can't garbage collect them.
+   */
+  @SuppressWarnings("unused")
+  private static native void clearCallbacks(JavaScriptObject script) /*-{
+    var nop = new Function('');
+    script.onerror = script.onload = script.onreadystatechange = nop;
+  }-*/;
+
   /**
    * Clear the success callback for fragment <code>fragment</code>.
    */
@@ -88,8 +100,9 @@
          return;
        }
        var head = document.getElementsByTagName('head').item(0);
-       head.removeChild(tag);
@com.google.gwt.core.client.impl.CrossSiteLoadingStrategy::clearOnSuccess(*)(fragment); + @com.google.gwt.core.client.impl.CrossSiteLoadingStrategy::clearCallbacks(*)(tag);
+       head.removeChild(tag);
loadfinishedhandl...@com.google.gwt.core.client.impl.asyncfragmentloader.loadterminatedhandler::loadTerminated(*)(
          exception);
      }
@@ -99,8 +112,9 @@
       JavaScriptObject tag) /*-{
      return function(code) {
        var head = document.getElementsByTagName('head').item(0);
-       head.removeChild(tag);
@com.google.gwt.core.client.impl.CrossSiteLoadingStrategy::clearOnSuccess(*)(fragment); + @com.google.gwt.core.client.impl.CrossSiteLoadingStrategy::clearCallbacks(*)(tag);
+       head.removeChild(tag);
        __gwtModuleFunction.installCode(code);
      }
    }-*/;

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to