[How-To] Detect memory leaks in Javascript

Many web developers often develop websites which results in memory leaks when viewing the websites in Internet Explorer. Most of these memory leaks often occur because of circular references between Javascript object and objects within IE’s DOM. 

Both the JavaScript engine and IE have independent memory management schemes. The JavaScript engine uses garbage collection to reclaim the memory allocated for JavaScript objects that are not used anymore.

Instead, an IE DOM object is a COM object; therefore its lifespan is ruled by a reference count. Both systems work perfectly in isolation but problems can arise when there are circular references between these two worlds as each side can’t see the entire cycle of these references.

For example, the following code (used to) generate a leak in IE6:

        <script language="JScript">
         var jsObject;
         function SetupLeak()
                jsObject = document.getElementById("LeakedDiv");
                document.getElementById("LeakedDiv").expandoProperty = jsObject;
    <body onload="SetupLeak()">
<div id="LeakedDiv"></div>

Here the SetupLeak() function creates a circular reference like this:

Java Script Leak

Java Script Leak

However, now debugging such memory leaks is easier to debug than before. JavaScript Memory Leak Detector (download) is a debugging tool to detect memory leaks in JavaScript code. It can be installed as an Internet Explorer band and it is expressly designed to find memory leaks in JavaScript code that runs in Internet Explorer.

Source: Microsoft Europe

Also read: Understanding HTTP Cookies

Batch Script for removing Internet Explorer 7 from your PC

[How-To]Save Keystrokes in Internet Explorer

Anti Spyware Applications: Here goes the ranking. 🙂


You can also follow me on Twitter at http://twitter.com/vaibhav1981

Do stay tuned to Technofriends for more, one of the best ways of doing so is by subscribing to our feeds. You can subscribe to Technofriends feed by clicking here.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: