JavaScript Memory Leak Detector (v2)

2011-03-20
3分钟阅读时长
598字
阅读

Introduction

JavaScript Memory Leak Detector (download) is a debugging tool to detect memory leaks and enforce best practices in JavaScript code when working with version of Internet Explorer older than IE8.

As described in detail in this MSDN article the JScript garbage collector in previous versions of Internet Explorer manages the lifetime of JScript objects but not of DOM objects. As a result, the JScript garbage collector cannot break circular references between DOM objects and JScript objects, and memory leaks may occur.

<div>
  <ul>
    <li>
      In IE6, these circular references are broken when the Internet Explorer process terminates (and leaks are very frequent).
    </li>
    <li>
      In IE7, these circular references are broken when users navigate away from the page.
    </li>
    <li>
      In IE8 the problem is completely mitigated. (Read <a href="http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=ie8whitepapers&ReleaseId=578">here</a> for more details).
    </li>
  </ul>
</div>

<p>
  Programmers who need to support older versions of the Internet Explorer browser should still try to pay attention to programming patterns such as JScript closures, as they could cause memory leaks.
</p>

<p>
  The leak detector works hosting an IE WebBrowser control and intercepting the execution of JavaScript inside IE. It monitors al the DOM elements in the markup of a web document that somehow interact with JavaScript and presents a list of potentially leaked objects to the user, together with information about the scripts loaded in the page and, if possible, a hint to the instruction that may have caused the leak.
</p>

<h4>
  Installation notes
</h4>

<p>
  IEJSLeaksDetector is a plain, native, Windows application and does not require any particular setup (the executable can be just unzipped and run).<br /> It only runs in 32 bit versions of Windows. 64 bits editions are not supported yet.
</p>

<p>
  There are only two installation steps required to make sure that the tool works correctly:
</p>

<p>
  1. The tool requires that the <strong>pdm.dll</strong> script installer is installed in the machine. This DLL is normally installed with any version of Microsoft Visual Studio.In case you are unable to install Visual Studio in the target machine, a simpler way to install pdm.dll is by installing the <strong>Microsoft Script Debugger</strong>, freely downloadable <a href="http://www.microsoft.com/downloads/details.aspx?familyid=2f465be0-94fd-4569-b3c4-dffdf19ccd99&displaylang=en">here</a>.
</p>

<p>
  2. The tool also requires Internet Explorer script debugging to be enabled to work correctly. Verify that the check box &#8220;Disable script debugging (Other)&#8221; is unchecked, in IE (&#8216;Tools&#8217; menu -> Internet Options -> &#8216;Advanced&#8217; tab -> &#8216;Browsing&#8217; section) as shown in figure.
</p>

<p>
  <img src="http://blogs.msdn.com/photos/gpdepix/images/7108465/original.aspx" alt="" width="380" height="474" />
</p>

<h4>
  How to use the tool
</h4>

<p>
  The user can start the memory profiling of a web application navigating to the desired URL. A new tab is opened with a WebBrowser control and a tree view shows all the documents and scripts that compose the current page.<br /> When the user has finished to interact with the page he can click the &#8220;Stop&#8221; button, which causes the tool to close the control and track possible leaks.<br /> Memory leaks are listed specifying the DOM object&#8217;s type and a list of &#8220;attached&#8221; JavaScript objects whose circular reference could be the cause of the leak. The tool also shows the call stack correponding to a memory leak, which represents the state of the script at the moment when the JavaScript object was attached to the DOM object. Finally, a script window highlights the exact point in the JavaScript code where the memory leak originated.<br /> More information can be found in the docs enclosed with the <a href="http://joinmicrosofteurope.com/files/IEJSLeaksDetector2.0.1.1.zip">binaries</a>.
</p>

<p>
  <img title="Javascript leaks detector" src="http://blogs.msdn.com/photos/gpdepix/images/9856180/original.aspx" alt="Javascript leaks detector" width="985" height="778" />
</p>

<p>
  &nbsp;
</p>
Avatar
zfkun 喜欢游戏、热爱技术、追求艺术、崇尚自由、渴望精彩、最爱唠叨