Google has open sourced Leak Finder, a tool inspecting the heap of JavaScript applications in order to find memory leaks.
As a garbage collected language JavaScript does not have the usual memory leaks typically found in other languages such as C++. But when memory is still allocated to objects that are no longer used it is said that the application has memory leaks, and if the leaks are important then the application may show reduced performance or even fail to execute.
One of the ways of possibly getting a memory leak in JavaScript is with circular references, especially when closures are used. Leak Finder can detect when a closure produces a leak, warning the developer and pointing to the faulty code. The tool looks for Google Closures’ goog.Disposable objects in the heap, verifying if the dispose() method was called and whether event listeners were released, because they can hold references to DOM objects, thus leaking memory.
Currently, Leak Finder works with Closures but it can be configured to work with other libraries. Closures is an open source JavaScript library containing widgets, an event framework, tools for DOM manipulation, a unit testing framework, animation tools, and other components, being used extensively across Google services such as GMail, GDocs, GMaps and others.
Also, code analysis must be done with Chrome 21 or later using remote debugging and the development tools.
Google open sourced in the past a number of other JavaScript tools such as the Closure Compiler, a tool generating compact and high performance code, Closure Templates for dynamically generating HTML, Closure Linter, a JavaScript style checker, and Closure Stylesheets, a set of extensions to CSS. GWT, another toolkit for building JavaScript applications, has had a release candidate in June, but its future is uncertain since Google has moved many of their GWT developers to Dart, which is seen as “an ambitious evolution of GWT’s mission to make web apps better for end users, and we’re optimistic about its potential.”