PRB: Memory Not Released Using Implicit Assignment With VBScript

ID: Q192551


The information in this article applies to:


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, please see the MSDN Web Workshop:

http://msdn.microsoft.com/workshop/default.asp
http://msdn.microsoft.com/scripting/

Additional query words: VBScript JScript Memory Usage


Keywords          : kbIE kbIE400 kbIE401 kbJScript kbScript kbIE401sp1 kbIE500 
Version           : WINDOWS:3.0,4.0,4.01,4.01sp1
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: April 30, 1999