Another Memory Leak Bites the Dust

As a web developer building the next web 2.0 site, you might not be thinking about how your JavaScript could be leaking memory and making the whole browser slow to crawl. Thanks to flaky garbage collectors in browsers (especially Internet Explorer) we have to always be on the lookout for those potential memory leaks. Fortunately for us, jQuery does its best to help you avoid memory leaks. In the latest revision of jQuery (Rev 2010) another potential memory leak has been avoided.

Lets say you need to run some code when the unload event fires. Simple enough, we just use .bind("unload", fn). However, in order for jQuery to help you avoid one of the biggest memory leaks in IE, it removes every single event, except unload event types, during the unload event. That means the unload event we just added has the potential to leak memory because it does not get removed. Except! The bind method now automatically uses the one method for unload event types. This means that once the unload event handler is finished, it is self removed and the leak is avoided! Thanks choan for a great patch to help jQuery help developers avoid those pesky memory leaks!

As a side note … Jack Slocum wrote a great concise post on avoiding memory leaks.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>