Leak finder for JavaScript helps web application developers find memory leaks in their JavaScript programs.
In garbage-collected languages, such as JavaScript, you cannot have traditional memory leaks by forgetting to free memory: when all references to an object are dropped, the object is garbage-collected and the memory is freed.
However, JavaScript programs can leak memory by unintentionally retaining references to objects. For example the references can be pointers to objects stored in a data structure in a JavaScript library (e.g., Closure) instead of the application code. If an object is unintentionally retained, all objects it points to are kept alive as well. This will lead to superfluous memory consumption.
Example (using the Closure JavaScript library):
goog.Disposable is an interface for disposable objects. Before dropping the last reference to an object which is an instance of goog.Disposable (or its subclass), the user code is supposed to invoke the method dispose()on the object. This method can release resources, e.g., by disposing event listeners. However, a web application might forget to call dispose() before dropping all the references to an object.
Leak finder can detect such goog.Disposable objects which were not disposed, and print out useful information (such as the stack trace when the object was created) about them. It produces machine-readable output and can be used as a part of test automation.
In order to find leaks, Leak Finder relies on goog.Disposable monitoring mode. The mode gathers all created but not yet disposed instances of goog.Disposable (and its subclasses) into an array goog.Disposable.instances_. This array will keep the objects alive. However, if an object is only kept alive by this array and other Closure data structures, it is a leak, since the user code doesn't contain any pointers to the object, and it cannot call dispose() on it.
Leak finder can be configured to detect other types of memory leaks and it can be used with JavaScript libraries other than Closure.
The Leak finder project page contains instructions for checking out the source code and using the tool.
By Marja Hölttä & Jochen Eisinger, Chrome team (Munich)
Thursday, 9 August 2012
Leak Finder: a new tool for JavaScript
Recent Posts
- New Google Tricks: 15+ Cool and Amazing Secret Hidden Google Tricks
- Weekend Tech News: Battlegrounds Mobile India gameplay, WhatsApp policy canceled?, OPPO foldable phone
- PUBG Mobile India release date: Relaunching as Battlegrounds Mobile India officially announced
- Difference B/W Blogs & Websites Things People Haven't Told You
- Watch Live IPL 2021: How to watch today's Live streaming of IPL 2021? All Methods
Label:
javascript,
open source release
Related tricks
- ReFr: A New Open-Source Framework for Building Reranking Models
- J2ObjC: A Java to iOS Objective-C translator
- Helping the World to Teach
- Leak Finder: a new tool for JavaScript
- JQUERY: Automatic Timed & Self-Closing Facebook Popup Like Box For Blogger
- JQUERY: Simple Accordion Drop Down Menu With Jquery & CSS
- Is JavaScript and jQuery are actually the same thing
- Pave Your Way to World of Web Design with Knowledge of Programming Languages
- Wicked Good XPath: a faster JavaScript XPath library
(+)