Microsoft KB Archive/192551

= PRB: Memory Not Released Using Implicit Assignment With VBScript =

Article ID: 192551

Article Last Modified on 8/8/2007

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * 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.



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
   Sub Button1_OnClick For j = 0 to 10000 t = "Now " s = t + "is " + "the " + "time " k = s + "for all good men." Next DisplayVB.innerHTML = "" + k + "" End Sub 

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

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

</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 = "" + k + "</B>" End Sub </SCRIPT> Perform the steps above and note that memory consumption does not increase.

<div class="references_section">