Skip to main content

Bug Tracker

Side navigation

Ticket #1731: 1731.diff
File 1731.diff, 1.2 KB (added by brandon, October 01, 2007 01:24PM UTC)

Patch

Index: src/event.js
===================================================================
--- src/event.js	(revision 3498)
+++ src/event.js	(working copy)
@@ -43,7 +43,7 @@
 		// Init the element's event structure
 		var events = jQuery.data(element, "events") || jQuery.data(element, "events", {});
 		
-		var handle = jQuery.data(element, "handle", function(){
+		var handle = jQuery.data(element, "handle") || jQuery.data(element, "handle", function(){
 			// returned undefined or false
 			var val;
 
@@ -69,6 +69,9 @@
 				element.addEventListener(type, handle, false);
 			else
 				element.attachEvent("on" + type, handle);
+			
+			// Add element to the event cache
+			this.cache.push(element);
 		}
 
 		// Add the function to the element's handler list
@@ -80,6 +83,7 @@
 
 	guid: 1,
 	global: {},
+	cache: [],
 
 	// Detach an event or set of events from an element
 	remove: function(element, type, handler) {
@@ -448,3 +452,10 @@
 	// A fallback to window.onload, that will always work
 	jQuery.event.add( window, "load", jQuery.ready );
 }
+
+
+// Remove events on window unload for IE to prevent memory leaks
+if ( jQuery.browser.msie )
+	jQuery(window).unload( function() {
+		jQuery( jQuery.event.cache ).unbind();
+	});

Download in other formats:

Original Format