PRB: Memory Not Released Using Implicit Assignment With VBScript (192551)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Visual Basic, Scripting Edition 3.0
  • Microsoft JScript 3.0

This article was previously published under Q192551

SYMPTOMS

When running an application in Internet Explorer that mixes VBScript and JScript, memory consumption and time to execute increase. Memory is not reclaimed until the page is refreshed or the browser closed.

CAUSE

When variables are assigned implicitly and then reassigned (as in a loop), separate copies of the variables appear to be made with each reassignment. Memory allocated to these variables is not reclaimed until the document is closed.

RESOLUTION

Variables in VBScript should be explicitly declared using the Dim statement.

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

Create a new HTML page using the code below. Using Performance Monitor or Windows NT Task Manager, monitor the memory usage of explorer.exe as you perform the following steps:
  1. Load the new HTML page into Internet Explorer.
  2. Click the button marked "Run JScript."
  3. Click the button marked "Run VBScript"
Note the additional memory consumed with each click of the button.

HTML Code Used to Reproduce Behavior

<HTML>
<HEAD>
<SCRIPT Language="VBScript">
   Sub Button1_OnClick()
      For j = 0 to 10000
         t = "Now "
         s = t + "is " + "the " + "time "
         k = s + "for all good men."
      Next
      DisplayVB.innerHTML = "<B>" + k + "</B>"
   End Sub
</SCRIPT>

<SCRIPT LANGUAGE="JScript">
function button2OnClick()
{
   for ( i = 0; i < 10000; ++i ) {
      t = "Now ";
      s = t + "is " + "the " + "time ";
      k = s + "for all good men.";
   }
   DisplayJS.innerHTML = "<B>" + k + "</B>";
}
</SCRIPT>
</HEAD>
<BODY BGColor="#FFFFF0">
   <font face="arial">
   <INPUT TYPE="Button" NAME="Button2" VALUE="Run JScript"
      onClick="button2OnClick()" style="width:100;">
   <BR><BR>
   <SPAN ID=DisplayJS></SPAN>
   <BR><BR>

   <INPUT TYPE="Button" NAME="Button1" VALUE="Run VBScript"
      style="width:100;">
   <BR><BR>
   <SPAN ID=DisplayVB></SPAN>
   <BR><BR>

</BODY>
</HTML>
				

Steps to Resolve

Change the VBScript block in the above sample to read as follows:
<SCRIPT Language="VBScript">
Sub Button1_OnClick()
   Dim j, t, s, k
   For j = 0 to 10000
      t = "Now "
      s = t + "is " + "the " + "time "
      k = s + "for all good men."
   Next
   DisplayVB.innerHTML = "<B>" + k + "</B>"
End Sub
</SCRIPT>
				
Perform the steps above and note that memory consumption does not increase.

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbpending kbprb kbScript KB192551