Skip to main content

Search and Top Navigation

#4565 closed bug (duplicate)

Opened May 30, 2009 05:44PM UTC

Closed October 16, 2012 02:18PM UTC

Creating a dialog leaks memory in IE6

Reported by: ncj102 Owned by:
Priority: major Milestone: 1.10.0
Component: ui.dialog Version: 1.7.1
Keywords: ie6 memory leak dialog Cc:
Blocked by: Blocking:
Description

I used IE 6.0.2800 on Windows 2000 SP1.

I am using the jQuery nightly build from May 28. I also included ui.core and ui.dialog at r2623.

Merely creating a dialog seems to cause the memory leak. Here is an example:

	<div id="box">
	hi
	</div>
	<script type="text/javascript" language="javascript">
	$(document).ready(function()
	{
		var box = $('#box');
		var boxOptions = { resizable: false,
			modal: false,
			autoOpen: false
		};

		var dialog = box.dialog(boxOptions);


	});
	</script>
 

I use sIEve to check for memory leaks. When I browse to a page containing the above, and then away, sIEve reports 12 memory leaks. If I use jQuery v1.3.2 instead of the nightly build, sIEve reports 9 memory leaks. Every time I refresh the page, it leaks about 1.3k. IE6 via MultipleIE on Windows XP seems to exhibit the same behavior, but I cannot attach sIEve to it. IE7 on XP does not appear to have this leak.

The patch supplied in #4188 by ivarsv does not prevent the memory leaks seen here, so I believe this issue is distinct.

Attachments (0)
Change History (6)

Changed June 01, 2009 03:33PM UTC by jzaefferer comment:1

milestone: TBD1.8

Changed July 07, 2009 10:57PM UTC by ncj102 comment:2

This does not seem to be specific to the dialog. If I create a new widget with no functionality, there is still a leak in IE6.

In the widget factory, if I comment out storage of the new object via "$.data" (lines 253 and 254), then the memory leak does not occur. There is a report in the jQuery bug tracker http://dev.jquery.com/ticket/4375 that indicates a memory leak with $.data when circular references are stored, but I can't yet confirm that as the cause of the problem.

Changed July 08, 2009 09:17PM UTC by ncj102 comment:3

There are actually several memory leaks in dialog when using IE6. They end up leaking the same DOM elements, so it's difficult to tell them apart. This may mean that there is one underlying problem, but I am not yet familiar enough with jQuery to find it. I have been able to find workarounds for every leak exercised by the original example, though I do not necessarily know why they work:

  • Applied the patch in #4188 to solve the widget factory leak I mentioned in the previous comment.
  • The event bound in disableSelection caused a circular reference of some kind. I added a line to the beginning of dialog.destroy that unbinds it by calling enableSelection:

self.uiDialog.find("*").enableSelection();
 

  • I make sure to call destroy for every dialog I create, on unload:

$(window).unload(function()
{
    box.dialog('destroy');
});
 

  • I made sure to set draggable to false, as draggable=true caused a leak.

Here is my (supposedly) leak free version of the original code:

	<script type="text/javascript" language="javascript">
		if ($.ui.version != '1.7.1')
		{
			debugger; //This patch may not apply any longer.
		}
		else
		{
			$.ui.dialog.prototype.destroy = function()
			{
				var self = this;

				self.uiDialog.find("*").enableSelection();

				(self.overlay && self.overlay.destroy());
				self.uiDialog.hide();
				self.element
			.unbind('.dialog')
			.removeData('dialog')
			.removeClass('ui-dialog-content ui-widget-content')
			.hide().appendTo('body');

				self.uiDialog.remove();

				(self.originalTitle && self.element.attr('title', self.originalTitle));

				return self;
			}
		}

		$(document).ready(function()
		{
			var box = $('#box');
			var boxOptions = { resizable: false,
				modal: false,
				autoOpen: false
			};

			box.dialog(boxOptions);
			
			$('#msg').text('Working2');

			$(window).unload(function()
			{
				box.dialog('destroy');
			});
		});
	</script>
 

Remember that this is only leak free in conjunction with the patch from #4188.

Changed June 14, 2011 03:08PM UTC by inspiraller comment:4

Ok, this is hilarious. I have been trying to figure out why using jquery ui dialog suddenly causes IE to go from 20kb to 350kb of memory. The reason is the css. Using @ symbols truly F**** IE. Also, if you have a lot of css, it screws it up too.

Changed October 11, 2012 02:47PM UTC by scottgonzalez comment:5

milestone: 1.9.01.10.0

Changed October 16, 2012 02:18PM UTC by bavanyo comment:6

resolution: → duplicate
status: newclosed

Duplicate of #4188.