Google Leak Finder Tackles JavaScript Memory Hogging

Google has developed a new tool called Leak Finder, and which is designed to help web application developers find memory leaks in their JavaScript programs.

Google’s Chrome team created the tool, as memory leaks can be common in browsers – particularly some versions of Microsoft’s Internet Explorer, developers say.

Memory Hogging

A memory leak occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code. A memory leak has symptoms similar to a number of other problems and often can only be diagnosed by a programmer with access to the program source code.

A memory leak can diminish the performance of the computer by reducing the amount of available memory. Eventually, in the worst case, too much of the available memory may become allocated and all or part of the system or device stops working correctly, the application fails, or the system slows down unacceptably.

Douglas Crockford, a JavaScript developer who is both a fan and critic of the language, as well as the creator of JavaScript Object Notation (JSON), said in a post on memory leaks: “When a system does not correctly manage its memory allocations, it is said to leak memory. A memory leak is a bug. Symptoms can include reduced performance and failure.” Crockford also noted, “In a memory space full of used cells, the browser starves to death.”

In an 8 August post about Leak Finder, Google’s Chrome team said, “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.”

Disposable Objects

Leak Finder for JavaScript works against the Developer tools remote inspecting protocol of Chrome, retrieves heap snapshots and detects objects which are “memory leaks” according to a given leak definition, Google said.

The Chrome team delivered goog.Disposable to help out with the leakage issue. 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,” the Chrome team wrote in the post. “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 goog.Disposable objects that were not disposed. It produces machine-readable output and can be used as a part of test automation.

To find leaks, Leak Finder relies on goog.Disposable monitoring mode. The mode gathers all created but not yet disposed instances of goog.Disposable. The default configuration of the tool detects goog.Disposable objects that were not disposed, Google said.

Are You An IT Olympian? Take our quiz.

Darryl K. Taft

Darryl K. Taft covers IBM, big data and a number of other topics for TechWeekEurope and eWeek

Recent Posts

Creating Deepfake Porn Without Consent To Become A Crime

People who create sexually explicit ‘deepfakes’ of adults will face prosecution under a new law…

16 hours ago

Google Fires 28 Staff Over Israel Protest, Undertakes More Layoffs

Protest at cloud contract with Israel results in staff firings, in addition to layoffs of…

17 hours ago

Russia Already Meddling In US Election, Microsoft Warns

Microsoft warns of Russian influence campaigns have begun targetting upcoming US election, albeit at a…

19 hours ago

EU To Drop Microsoft’s OpenAI Investment Probe – Report

Microsoft to avoid an EU investigation into its $13 billion investment in OpenAI, after EC…

22 hours ago

US Provides Assurances For Julian Assange Extradition

As President Biden 'considers' request to drop Julian Assange extradition, US provides assurances to prevent…

24 hours ago