Skip to main content

Bug Tracker

Side navigation

#7842 closed bug (invalid)

Opened December 25, 2010 03:25AM UTC

Closed January 08, 2011 08:07AM UTC

Mmeory leak in support code

Reported by: chancharles Owned by: chancharles
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

The following code will cause the "div" to leak in IE8:

	if ( div.attachEvent && div.fireEvent ) {
		div.attachEvent("onclick", function click() {
			// Cloning a node shouldn't copy over any
			// bound event handlers (IE does this)
			jQuery.support.noCloneEvent = false;
			div.detachEvent("onclick", click);
		});
		div.cloneNode(true).fireEvent("onclick");
	}

	div = document.createElement("div");

To fix this problem, we can add:

div.outerHTML = '';

before the div assignment:

div.outerHTML = '';
div = document.createElement("div");

This is IE specific.

Attachments (0)
Change History (3)

Changed December 25, 2010 03:32AM UTC by chancharles comment:1

The following "null" assignments will also cause memory leak in IE8:

	var eventSupported = function( eventName ) {
		var el = document.createElement("div");
		eventName = "on" + eventName;

		var isSupported = (eventName in el);
		if ( !isSupported ) {
			el.setAttribute(eventName, "return;");
			isSupported = typeof el[eventName] === "function";
		}
		el = null;

		return isSupported;
	};

	jQuery.support.submitBubbles = eventSupported("submit");
	jQuery.support.changeBubbles = eventSupported("change");

	// release memory in IE
	root = script = div = all = a = null;

We can change them to:

	var eventSupported = function( eventName ) {
		var el = document.createElement("div");
		eventName = "on" + eventName;

		var isSupported = (eventName in el);
		if ( !isSupported ) {
			el.setAttribute(eventName, "return;");
			isSupported = typeof el[eventName] === "function";
		}

                el.outerHTML = '';
		el = null;

		return isSupported;
	};

	jQuery.support.submitBubbles = eventSupported("submit");
	jQuery.support.changeBubbles = eventSupported("change");

	// release memory in IE
        script.outerHTML = '';
        div.outerHTML = '';
	root = script = div = all = a = null;

Changed December 25, 2010 03:53AM UTC by rwaldron comment:2

owner: → chancharles
status: newpending

Thanks for taking the time to contribute to the jQuery project!

Is there any way that you can show evidence of this memory leak?

Changed January 08, 2011 08:07AM UTC by trac-o-bot comment:3

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!