Experiment Objective: To verify the value of active free memory variable.
Experiment Original code:
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
' Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
' temp1= ' "' Switch variable
' Temp2 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
Memory Change screenshot 1:
Screenshot explanation: The CPU waveform change is caused by the page automatic refresh, do not care! What we're looking at is a change in the memory line. This is the original state, and the memory line remains unchanged at all levels.
OK, the following experiment is officially started:
First step:
Put the original code in the
' Temp1 = Space (1024*1024*50) ' 50MB
The previous annotation number ' removed, changed to
Temp1 = Space (1024*1024*50) ' 50MB
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
' temp1= ' "' Switch variable
' Temp2 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
And then watch the memory change for some time.
Memory Change screenshot 2:
Results: The memory starts to appear square wave.
Step Two:
And then put
' Temp2 = Space (1024*1024*50) ' 50MB
The previous annotation number ' removed, changed to
Temp2 = Space (1024*1024*50) ' 50MB
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
' temp1= ' "' Switch variable
Temp2 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
Memory Change screenshot 3:
Result: The square wave is taller than the original one layer, becomes the ladder shape.
Step Three:
And then put
' temp1= ' "' Switch variable
The previous annotation number ' removed, changed to
temp1= "" ' Switch variable
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
temp1= "" ' Switch variable
Temp2 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
See if you can free the memory space occupied by the first variable
Memory Change screenshot 4:
The result: Obviously, the second wave front is missing, and it appears that the release was successful.
Fourth Step:
We first restore the code to the original code, and so the memory smooth down, then the first three steps to do a quick, so that in the same screenshot to compare the changes in memory.
Memory Change screenshot 5:
Results: You can clearly see the difference in three different situations. Without LUN execution time and memory footprint, the active release of the variable is better than the passive release.
Fifth Step:
Then the third step of the code, put
temp1= "" ' Switch variable
Temp2 = Space (1024*1024*50) ' 50MB
Change into
' temp1= ' "' Switch variable
Temp1 = Space (1024*1024*50) ' 50MB
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
' temp1= ' "' Switch variable
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
Memory Change screenshot 6:
Result: Look at the next step before you give the conclusion
Sixth step:
Put
' temp1= ' "' Switch variable
Change into
temp1= "" ' Switch variable
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
temp1= "" ' Switch variable
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
See if the results will be different.
Memory Change screenshot 7:
Results: With the same variable name, even if the value, the original occupied space can not be released or replaced (screenshot 6), and so the program passive release, the use of time than manual slow (comprehensive screenshot 6, 7 description).
Below the
temp1= "" ' Switch variable
Temp1 = Space (1024*1024*50) ' 50MB
Change the position of two sentences
Temp1 = Space (1024*1024*50) ' 50MB
temp1= "" ' Switch variable
<script Language=vbscript runat=server> Dim TEMP1,TEMP2
Temp1 = Space (1024*1024*50) ' 50MB
For i = 0 to 5000000 ' latency Next
Temp1 = Space (1024*1024*50) ' 50MB
temp1= "" ' Switch variable
For i = 0 to 5000000 ' latency Next
Response.Write "<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >" </script>
|
After the screenshot 8:
Results: It can be seen that the active release takes less time than the passive (wave tip)
Experimental Conclusion:
The initiative to release the memory is useful, not some people say to wait for the end of the page to release, or just stay at the end of the program and automatic release, but in the implementation process can also be artificially controlled. In particular, the program needs to call several large volume variables, as soon as possible to release the useless variables, not only can reduce the burden on the server, but also can speed up the operation of the program.
If the procedure or conclusion is found to be incorrect, please correct me.
Finally, on the use of "", empty or null to release, the results are basically the same, interested in the ability to personally compare to try. As for the use of which to release the variable more formal or more efficient, I can not judge in this experiment, I would like to know friends to teach.
(Source: Viphot)