Skip to main content

Bug Tracker

Side navigation

#11757 closed bug (fixed)

Opened May 11, 2012 06:54PM UTC

Closed June 22, 2012 02:28PM UTC

Last modified October 09, 2013 01:22PM UTC

IE 8 memory accumulation in iframes with jQuery 1.7.2

Reported by: adamki@microsoft.com Owned by:
Priority: low Milestone: 1.8
Component: support Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

jQuery content in iframe isn't cleared if you leave the iframe in IE 8. Here is a simple example.

top.htm
<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="X-UA-Compatible" content="IE=8"/>
</head>
<body>
<a href="about:blank">about:blank</a><br/>
<iframe src="iframe.htm"></iframe>
</body>
</html>

iframe.htm
<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="X-UA-Compatible" content="IE=8"/>
 <script src="jquery.js" type="text/javascript"></script>
</head>
<body>
 <a href="iframe.htm">iframe</a>
</body>
</html>

Click link in iframe to repeatedly "leak" memory in IE 8. Then click the about:blank link to see memory levels EVENTUALLY return (doesn't return right away unless, oddly, you add a reference to jquery.js in the top page as well).

To fix the leak, make this modification to the jquery.js file. Add the two lines and modify the attachEvent call as noted.

jQuery.support = (function() {
…
       var onclicktmp = null;  // adamki - added
       if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {   
              div.attachEvent( "onclick", onclicktmp = function() {  // adamki - added the assignment to onclicktmp
                     // Cloning a node shouldn't copy over any
                     // bound event handlers (IE does this)
                     support.noCloneEvent = false;
              });
              div.cloneNode( true ).fireEvent( "onclick" );
              div.detachEvent( "onclick", onclicktmp);  // adamki added
       } 

I made the change because I noticed the event handler was never removed from the div.

Attachments (0)
Change History (8)

Changed May 16, 2012 10:41AM UTC by sindresorhus comment:1

component: unfiledsupport
priority: undecidedlow
status: newopen

Confirmed. The memory grows about 500kb on each click.

Live testcase: http://wroug.com/stuff/testcases/iframe-memleak-ie8/

Live testcase without jQuery: http://wroug.com/stuff/testcases/iframe-memleak-ie8/index-without-jquery.html

Changed May 31, 2012 08:49PM UTC by anonymous comment:2

Our software team also discovered that this memory leak exists in ie 6.0 and 7.0. Downgrading the version of Jquery to 1.7.1 resolved the memory leak issue. On some pages we were loosing up to 1.5 megs per page refresh.

Changed June 21, 2012 04:21PM UTC by anonymous comment:3

Wow! This was causing huge memory leaks for us! We have iframes imbedded 3 layers deep (multiple iframes in iframes) and was causing 100mb memory jumps each time a page was loaded, this is a very important issue for us, I hope there is a fix soon.

Changed June 22, 2012 02:28PM UTC by Dave Methvin comment:4

resolution: → fixed
status: openclosed

Fix #11757. IE 6/7 can't clean up circular DOM-JS refs.

Why? Because it's dumb. Verified with the case in the ticket.

Changeset: ad8dc12ac28915891127666d5b6c2d3200d1e79c

Changed June 22, 2012 07:40PM UTC by dmethvin comment:5

milestone: None1.8

Changed July 16, 2012 01:09PM UTC by Pradeep comment:6

Can jquery confirm fix for #11757 is included in 1.8 ;

JQuery Release 1.8B2 change log does not show #11757

Changed October 04, 2012 08:15PM UTC by anonymous comment:7

I can find the same code on version 1.7.1

Changed October 09, 2013 01:22PM UTC by quentin comment:8

I still have leaks with IE 8 and the same testcase. Tested with versions 1.8.2 and 1.10+.