Opened 10 years ago

Closed 10 years ago

#7793 closed bug (fixed)

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:


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.

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)
		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'));
	width: this.width(),
	height: this.height()

Change History (1)

comment:1 Changed 10 years ago by Florian Gutmann

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

Note: See TracTickets for help on using tickets.