Opened 10 years ago

Closed 7 years ago

#4565 closed bug (duplicate)

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.

Change History (6)

comment:1 Changed 10 years ago by Jörn Zaefferer

Milestone: TBD1.8

comment:2 Changed 10 years ago by ncj102

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.

comment:3 Changed 10 years ago by ncj102

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.

comment:4 Changed 8 years ago by inspiraller

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.

comment:5 Changed 7 years ago by Scott González

Milestone: 1.9.01.10.0

comment:6 Changed 7 years ago by bavanyo

Resolution: duplicate
Status: newclosed

Duplicate of #4188.

Note: See TracTickets for help on using tickets.