Very handy Javascript memory leak detector

I used this tool recently and found it to be very helpful in detecting memory leaks related to closures and circular references (between JS and DOM). 

http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector.aspx

I have found that many memory leaks are a result of one of the following scenarios:

1. An event handler attribute on a DOM element references a javascript function which "closes" over a reference to the same element. This sets up a circular dependency and prevents both the JS and DOM garbage collectors from doing their job fully.

2. When using a virtual closure technique like the one described here: http://laurens.vd.oever.nl/weblog/items2005/closures/ the "sender" (e.g. "this") object can have a property referencing the DOM element with the event that is being subscribed to. In this case, a similar circular reference is created.

Developers should also take precautions when it comes to using the onreadystatechanged event of an XMLHttpRequest object. If the handler is a closure that closes over a reference to the same XMLHttpRequest object, another circular dependency can be created. This isn't necessairly detected by the above tool because the object is not part of the DOM.

Published 22 August 08 12:34 by brettern

Comments

No Comments
Anonymous comments are disabled

Search

This Blog

Syndication

Page view tracker