JavaScript Memory Leak Detector

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.
  • In IE6, these circular references are broken when the Internet Explorer process terminates (and leaks are very frequent).
  • In IE7, these circular references are broken when users navigate away from the page.
  • In IE8 the problem is completely mitigated. (Read here for more details).

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.

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.

Installation notes

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

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

1. The tool requires that the pdm.dll 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 Microsoft Script Debugger, freely downloadable here.

2. The tool also requires Internet Explorer script debugging to be enabled to work correctly. Verify that the check box "Disable script debugging (Other)" is unchecked, in IE ('Tools' menu -> Internet Options -> 'Advanced' tab -> 'Browsing' section) as shown in figure. 

JavaScript Memory Leak Detector_第1张图片

How to use the tool

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.
When the user has finished to interact with the page he can click the "Stop" button, which causes the tool to close the control and track possible leaks. 
Memory leaks are listed specifying the DOM object's type and a list of "attached" 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.
More information can be found in the docs enclosed with the binaries.

JavaScript Memory Leak Detector_第2张图片
 


 这是来自微软GPDE团队的一个小工具,下面简称JLD

       官网:http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector.aspx
       安装后,我们可以在ie浏览器的 查看->浏览器栏中找到

JavaScript Memory Leak Detector_第3张图片

      JLD强大之处在于能够模拟IE6和IE7的GC情况,和真实的回收情况。这样可以做一个比较。

JavaScript Memory Leak Detector_第4张图片  
     这里通常能只能反应IE6和IE7的理想情况,我们需要选择下面Actual Leaks来反映当前浏览器的真实情况。

JavaScript Memory Leak Detector_第5张图片

          浏览器刷新后,我们就可以看到上次页面的结果了,绿色代表没有发现内存泄露,红色代表发现了内存泄露,蓝色是当前加载完成的页面,当然还有黑色,是指正在加载的网页
        当我们展开一个有问题的页面时,

       我们可以看到一个有问题分支Leaks.这里列出了有问题的节点,同时还能帮我们列出出现问题的脚本在什么地方。 

        这点非常方便我们定位出泄露的问题所在。不过要使用脚本调试,我们必须要打开ie的脚本调试功能

        在ie选项的高级中,我们去掉这两个勾即可 


你可能感兴趣的:(JavaScript Memory Leak Detector)