jQuery is very small and useful javascript library which is a must for every developer related to web. I also have used jQuery in my applications a lot, but recently i found that jQuery is leaking memory which is causing trouble to my applications,so be careful while using your selectors and creating dynamic DOM elements by using jQuery.In this article i will discuss the simple ways to track the memory leak in your application and comments related to optimizing and reducing the memory leaks using jQuery are always welcome.

How to detect the memory leak in your web application There is a very simple tool available on web known as “Drip” which can help you to test the memory leaks in your web applications You can download drip from http://www.outofhanwell.com/ieleak/Drip-0.5.exe Documentation of drip is available at https://ieleak.svn.sourceforge.net/svnroot/ieleak/trunk/drip/docs/index.html Drip can catch the memory leaks inside the boundary of Internet Explorer but not outside its boundary. A typical run on one of my applications which is fully jQuery dependent gives me these results. What Drip does is that it unloads the page and checks for the memory leaks which remained even after the page was unloaded. Given below is the drip test on jQuery.com As you can see that jQuery.com also have some memory leak which seems to be a bug to me in jQuery code itself. On some research on net i found that commenting out few lines of code in the jQuery itself can reduce some of the memory leaks in your application but still the memory leak is there and doesn’t leave you, might be in future we get some bug fix on this memory leak thing from the jQuery team. The lines of code commenting which can do little magic is found inside the jQuery library

if ( div.attachEvent && div.fireEvent ) {
		div.attachEvent("onclick", function(){
			// Cloning a node shouldn't copy over any
			// bound event handlers (IE does this)
			jQuery.support.noCloneEvent = false;
			div.detachEvent("onclick", arguments.callee);
		});
		div.cloneNode(true).fireEvent("onclick");
	}

If any one of you have some other tips and tricks to reduce this memory leaking and any other way to prevent it.Do post comments to help the community and also help a lot of jQuery developers and jQuery itself to be a bug free library.

Happy Programming!!!