Loading ...
Sorry, an error occurred while loading the content.
 

Calling Panel.show() on "beforeunload" resulting in memory leak

Expand Messages
  • radbrad_harris
    In the application I m working on we pull up a processing panel that is done by calling show on it from a listener to the window beforeunload event.
    Message 1 of 3 , Dec 26, 2007
      In the application I'm working on we pull up a "processing" panel that
      is done by calling "show" on it from a listener to the window
      "beforeunload" event. I've noticed that this is causing a memory leak
      in IE6 and 7, most likely because for some reason it can't garabage
      collect some/all of the doms associated with the panel.

      Before I switch from using a Panel to something a bit simpler and
      homegrown to try and solve the problem, I was wondering if anyone else
      has encountered this problem or has input on it. Thanks.
    • radbrad_harris
      ... I tracked the problem down to a subscriber to the panels beforeShowEvent . That method subscribed was creating a YAHOO.util.Element object to change some
      Message 2 of 3 , Dec 27, 2007
        --- In ydn-javascript@yahoogroups.com, "radbrad_harris"
        <radbrad_harris@...> wrote:
        >
        > In the application I'm working on we pull up a "processing" panel that
        > is done by calling "show" on it from a listener to the window
        > "beforeunload" event. I've noticed that this is causing a memory leak
        > in IE6 and 7, most likely because for some reason it can't garabage
        > collect some/all of the doms associated with the panel.
        >
        > Before I switch from using a Panel to something a bit simpler and
        > homegrown to try and solve the problem, I was wondering if anyone else
        > has encountered this problem or has input on it. Thanks.
        >


        I tracked the problem down to a subscriber to the panels
        "beforeShowEvent". That method subscribed was creating a
        YAHOO.util.Element object to change some css styles on a dom inside of
        the panel. Changing the approach to not use a full YAHOO.util.Element
        object, and just using YAHOO.util.Dom.setStyle got rid of the leak.

        I was able to reproduce the memory leak in the following scenario,
        which simply creates an Element object during the "beforeunload" event
        of the window. The listener can be a closure as below, or a
        reference, they both leak. On my machine it leaks about 120K per request:

        <html>
        <head>
        <script type="text/javascript"
        src="yui_2.4.1/yahoo-dom-event/yahoo-dom-event.js"></script>
        <script type="text/javascript"
        src="yui_2.4.1/element/element-beta.js"></script>
        </head>
        <script type="text/javascript">
        YAHOO.util.Event.addListener(window, 'beforeunload', function() {
        var el = new YAHOO.util.Element('leak-tester');
        });
        </script>
        <body>
        <div id="leak-tester"></div>
        </body>
        </html>
      • radbrad_harris
        submitted as a bug: http://sourceforge.net/tracker/index.php?func=detail&aid=1859050&group_id=165715&atid=836476
        Message 3 of 3 , Dec 27, 2007
        Your message has been successfully submitted and would be delivered to recipients shortly.