Circular reference in xforms javascript causing IE memory leak

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Circular reference in xforms javascript causing IE memory leak

Anne Torres
Hi, 

In xforms.js, the setInterval for the heartbeat callback (see code below) was created in the context of the XForms document object, meaning it had a reference to a significant number of DOM objects. This creates a circular reference between DOM objects and javascript objects which causes memory leaks in IE6.

	// A heartbeat event - An AJAX request for letting server know that "I'm still alive"
        if (ORBEON.util.Properties.sessionHeartbeat.get()) {
            var heartBeatDelay = ORBEON.util.Properties.sessionHeartbeatDelay.get();
            if (heartBeatDelay > 0) {
                window.setInterval(function() {
                    ORBEON.xforms.Events.sendHeartBeatIfNeeded(heartBeatDelay);
                }, heartBeatDelay / 10); // say session is 30 mn, heartbeat must come after 24 mn, we check every 2.4 mn so we should
            }
        }


Test case: 
1. Load a form in an iframe - for some reason, the issue is more evident when the form is in a frame. Use IE6 browser.
2. Open up task manager or any other tool to check the memory usage of IE.
3. Refresh page or reload the form.
4. Check task manager - memory usage goes up everytime you refresh page or reload the form in the iframe.

Attached is a patch for the solution where we extracted the anonymous function from the heartbeat callback so that it will not hold unnecessary reference to objects in the document object.

Thanks, 
Anne


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws

0001-Fix-Client-Side-Memory-Leak-in-IE6-caused-by-setInte.patch (2K) Download Attachment