Skip to main content

Search and Top Navigation

#7793 closed bug (fixed)

Opened October 14, 2011 03:05PM UTC

Closed October 14, 2011 03:19PM UTC

Small memory leak in ui dialog

Reported by: fgutmann Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.dialog Version: 1.8.16
Keywords: Cc:
Blocked by: Blocking:
Description

JQuery UI keeps old instances of overlays to reuse them later.

This is done to solve a memory leak in ie (see bug #5185).

Unfortunately the implementation of reusing the overlay itself introduces a small memory leak which can be easily fixed.

The code which takes the old instance appends it to the body and then assigns it as new $el. Because this is done in one jQuery expression the $el selector attribute get's longer for every dialog. Also the prevObject property is added every time again.

Have a look at the simple example which opens and destroys 100 modal dialogs. Afterwards it outputs the selector property of jQuery.ui.dialog.overlay.oldInstances[0].selector.

http://jsfiddle.net/nfy97/1/

The fix is simple and easy to understand.

In jquery.ui.dialog.js version 1.8.16 on line 763 The code looks like this:

var $el = (this.oldInstances.pop() || $('<div></div>').addClass('ui-widget-overlay')).appendTo(document.body)
	.css({
		width: this.width(),
		height: this.height()
	});

It just needs to be changed so that $el is assigned first and then appended to the body.

var $el = (this.oldInstances.pop() || $('<div></div>').addClass('ui-widget-overlay'));
$el.appendTo(document.body).css({
	width: this.width(),
	height: this.height()
});
Attachments (0)
Change History (1)

Changed October 14, 2011 03:19PM UTC by Florian Gutmann comment:1

resolution: → fixed
status: newclosed

Dialog: fix small memory leak when having lot's of instances. Fixes #7793 - Small memory leak in ui dialog.

Changeset: 42d33f2f86d48f5f82a640a6c57c566a4e84cdda