Results 1 to 6 of 6

Thread: Microsoft JavaScript Memory Leak Detector

  1. #1
    Join Date
    Mar 2008
    Posts
    198

    Microsoft JavaScript Memory Leak Detector

    Paoli Severini from Microsoft's Global Product Development Team has released a tool called JSLeaks Detector which facilitates finding memory leaks in Internet Explorer.

    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. The tool is currently in beta.

    This will allow a simple way to test your pages for memory leaks and be aware of when you are leaking memory.

    Screenshot:




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

    Code:
    <html>
        <head>
            <script language="JScript">
             var jsObject;
             function SetupLeak()
             {
                    jsObject = document.getElementById("LeakedDiv");
                    document.getElementById("LeakedDiv").expandoProperty = jsObject;
             }
         </script>
        </head>
        <body onload="SetupLeak()">
            <div id="LeakedDiv"></div>
        </body>
    </html>
    Here the SetupLeak() function creates a circular reference like this:





    How does it work?

    Like any IE Band, the JavaScript Memory Leak Detector is a COM in-process DLL loaded in the Internet Explorer process. The fact of living inside the IE process allows it to easily intercept some of the API calls made by the IE code. In this case, we are interested in intercepting every call that creates a Jscript engine.

    The Jscript engine is a COM object, and it is instantiated by Trident (mshtml.dll) with a call to CoCreateInstance(). Therefore, the first operation made by the tool will be to intercept the calls to CoCreateInstance made by the mshtml module. There are a few ways to implement this API hooking; in this case the simple technique of overwriting the module Import Table in memory works perfectly. (See Robbins’ “Debugging Applications” for more details).

    At this point we can substitute our own Jscript engine in place of the real engine. By implementing all the ActiveScript interfaces exposed by a Jscript engine and delegating all the calls to an instance of the real Jscript engine, the tool can transparently intercept all the interactions between Trident and Javascript and still have Internet Explorer to run correctly.

    Now, a Jscript engine by itself has no notions of Internet Explorer and its DOM objects. It is IE that registers the root (window) object to the engine and loads into the engine all the scripts contained or loaded by a HTML document. Since we are intercepting all the calls to Jscript, we can thus have a reference to all the DOM objects that are passed to or used by a Javascript function.

    The technique to do this is a bit tricky. A DOM object is passed to (and accessed by) Jscript through an IDispatch interface; so for each new object that we meet we create a fake COM object that works as interceptor (or wrapper), exposing IDispatch and delegating the calls to the real (contained) IDispatch object.

    Every time a method or property is called to a DOM element by JavaScript, the call is actually made to our wrapper and then delegated to the real object. The wrapper can analyse the method in/out parameters and return value, looking for other IDispatch pointers that represent new DOM objects. If it finds a new IDispatch pointer not yet met, we know that this object will now be visible to the JavaScript code, and we need to build another wrapper and pass it to JavaScript in its place. In the end, every JavaScript function will access DOM objects only through these wrappers and the tool will have complete control over the script execution.
    It installs as a plugin to IE6 and IE7 under both Windows XP & Windows Vista.

    More info: JavaScript Memory Leak Detector

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Microsoft JavaScript Memory Leak Detector

    I have installed this tool few weeks ago only and its good and tested this on one of my JavaScript application. Looks like Its clean of memory leaks.

  3. #3
    Join Date
    Apr 2009
    Posts
    15

    Re: Microsoft JavaScript Memory Leak Detector

    I have installed the this JavaScript Memory Leak Detector tool wiotut any issue, but whenever i try to run the detector, the IE gets crash. THis happens every time i run detector.

  4. #4
    Join Date
    Mar 2008
    Posts
    198

    Re: Microsoft JavaScript Memory Leak Detector

    As its still in beta version so obviously it will give some issues and errors, we have to wait for next or final release to get the error free version of this tool.

  5. #5
    Join Date
    Sep 2011
    Posts
    1

    Re: Microsoft JavaScript Memory Leak Detector

    Does any one know if there is a new version for IE9 or another tool that runs with IE9?
    I need a javascript memory leak detector for IE9.
    Thanks in advance

  6. #6
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Microsoft JavaScript Memory Leak Detector

    Quote Originally Posted by Luis Silva View Post
    Does any one know if there is a new version for IE9 or another tool that runs with IE9?
    I need a javascript memory leak detector for IE9.
    Thanks in advance
    i dont think there are any JavaScript Memory Leak Detector for IE9 or such but below is basic idea of the leak, which is to repeatedly execute the following:

    Code:
    function leak1() {
        var node = document.getElementById("TO_AREA");
        node.innerHTML = "<img>";
        node.innerHTML = "";
        node = null;
    }

Similar Threads

  1. svchost.exe consumes CPU and Memory - Memory Leak?
    By Chad Gross in forum Windows XP Support
    Replies: 1
    Last Post: 25-03-2013, 12:46 PM
  2. Memory Leak 60 to 30-40 fps in Crysis 2
    By Krisoijn in forum Motherboard Processor & RAM
    Replies: 5
    Last Post: 25-03-2011, 10:16 PM
  3. Memory leak problems in C++
    By Protectors in forum Software Development
    Replies: 9
    Last Post: 02-07-2010, 07:09 AM
  4. How to compare states of memory in memory leak?
    By Bottlenecked in forum Windows Software
    Replies: 4
    Last Post: 24-06-2010, 06:35 AM
  5. Firefox memory leak
    By Waffle in forum Technology & Internet
    Replies: 3
    Last Post: 20-08-2009, 11:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,465,806.23118 seconds with 17 queries