Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: Memory leak occurs when you remove behaviors


View products that this article applies to.

Symptoms

When you remove large behaviors, the memory usage does not decrease.

↑ Back to the top


Cause

Scripting engines do not include a mechanism to enable Internet Explorer to force the release of certain internal objects.

↑ Back to the top


Resolution

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

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

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.

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB315014, kbscript, kbpending, kbdhtml, kbbug

↑ Back to the top

Article Info
Article ID : 315014
Revision : 4
Created on : 1/17/2005
Published on : 1/17/2005
Exists online : False
Views : 368