Opened 15 years ago

Closed 15 years ago

#2364 closed defect (duplicate)

memory leak in dojo.event.connect/dojo.event.disconnect

Reported by: guest Owned by: anonymous
Priority: high Milestone: 0.9
Component: Core Version: 0.4.1
Keywords: event connect disconnect memory leak Cc:
Blocked By: Blocking:


Nodes being dynamically created, connected, unconnected and destroyed after all will leak memory both in IE and FF. The loss is small but crucial for single-page applications where a lot of nodes are being created and connected via dojo.event.connect.

See the example code below or check out the live demo on and watch your browser's memory consumption grow in Process Explorer or a similar tool.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
		<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
		<title>Testcase Context Menu Memory Leak</title>
		<script type="text/javascript" src="dojo/dojo.js" ></script>

		<script language="JavaScript" type="text/javascript">

		<script language="JavaScript" type="text/javascript">

			var amount = 0;

			function Test() {

				// create element
				var element = document.createElement('div');
				document.getElementById('amount').innerHTML = amount;

				// connect test function on onclick event				
				dojo.event.connect(element, 'onclick', this, 'MyOnclickFunction');

				// disconnect event
				dojo.event.disconnect(element, 'onclick', this, 'MyOnclickFunction');

				// remove element

			function StartTest() {
				task = window.setInterval("Test()", 100);
				document.getElementById('state').innerHTML = 'Running';

			function StopTest() {
				document.getElementById('state').innerHTML = 'Not running';
			function MyOnclickFunction() {
				return true;


	<body style="font-family:Arial;font-size:13px;">
			<button name="stressTest" type="button" onclick="StartTest();">Start Test</button> 
			<button name="stressTest" type="button" onclick="StopTest();">Stop Test</button>
		<p><b>State:</b> <span id="state">Not running</span> / <b>Amount of elements created:</b> <span id="amount">0</span></p>

Change History (6)

comment:1 Changed 15 years ago by Eugene Lazutkin

I cannot reproduce it on FF2/Windows with posted code.

comment:2 Changed 15 years ago by guest

Sorry, didn't mention I reproduced it in FF 1.5/Win and in IE6 + IE7. Memory consumption grows in FF slower though and starts after having created about 150 nodes or so...

comment:3 Changed 15 years ago by Adam Peller

Is this a dup of #1727? Is dojo.event.connect at fault or node.removeChild? Can you post an e-mail address in case we need to contact you later?

comment:4 Changed 15 years ago by guest

Sorry - seems to be my fault. The following lines fixed the leak:

// remove element
/* document.body.removeChild(element); (leak was here) */

var node = dojo.dom.removeNode(element);

Just wondering: Wouldn't it be dojo.event.disconnect's job to *really* remove everything from a previously connected node in order to prevent memory leaks (like setting events to null etc.)? This may be a stupid question since I don't know exactly what's necessary to prevent leaks for all browsers, but using dojo.event.disconnect I thought I'm doing everything correctly...

Thx! (m dot reufer at bag dot ch)

comment:5 Changed 15 years ago by dylan

Milestone: 0.9
Priority: highnormal

comment:6 Changed 15 years ago by Adam Peller

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.