Ticket #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: | ||
| Blocking: | Blocked by: |
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.
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()
});


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