BUG: Memory leak occurs when you remove behaviors

This article was previously published under Q315014
This article has been archived. It is offered "as is" and will no longer be updated.
When you remove large behaviors, the memory usage does not decrease.
Scripting engines do not include a mechanism to enable Internet Explorer to force the release of certain internal objects.
To release the memory, browse to another location, or refresh the page.
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
309170 Memory leak occurs when behaviors are dynamically removed
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Steps to Reproduce the Behavior

  1. Use the following code to create a behavior named Leak.htc:
    <public:component tagname="Leak0"><public:attach event="ondocumentready" onevent="Init()"/><SCRIPT LANGUAGE="JScript">var m_div = null;function Init(){  m_div = document.createElement("div");  m_div.innerText = "This page demonstrates memory leaks with behaviors";  element.appendChild(m_div);}// Comment lines also increase the size of the behavior. Copy this 200 times to see larger leaks.</script></public:component>					
  2. Use the following code to create a Hypertext Markup Language (HTML) file named Leak.htm to test the behavior:
    <html xmlns:leaktest><body>  <?import namespace="leaktest" implementation="Leak.htc" />  <script>  function LeakMe()  {    var x;    for (x = 0; x < 100; x++)    {      myDiv.innerHTML = "<leaktest:Leak0/>";    }    myDiv.innerHTML = "empty div";  }  </script>  <div id="myDiv" style="background: yellow;">My Div</div>  <br>  <button onclick="LeakMe()">Leak Me (insert htc 100x into div)</button></body></html>					
  3. Use the following code to create a simple page named Simple.htm:
    <html><body><a href="leak.htm">Leak Page</a></body></html>					
  4. Open Task Manager.
  5. Double-click Simple.htm to run Internet Explorer.
  6. Find the Internet Explorer process in Task Manager. Notice the memory usage.
  7. Browse to Leak.htm. Notice the memory usage. Click the button several times. Every time that you click the button, a new behavior is set within the DIV tag 100 times. This removes the previous behavior, if any. Notice that the memory usage increases significantly.
  8. To return the memory to a reasonable level, return to Simple.htm, or refresh the page. When you return to Simple.htm or refresh the page, the browser may stop responding for a short time period. This is because the browser must clean up the internal data structures for each inserted behavior.

Article ID: 315014 - Last Review: 10/24/2013 09:07:16 - Revision: 4.0

  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer (Programming) 6.0
  • kbnosurvey kbarchive kbbug kbdhtml kbpending kbscript KB315014