Objective: To test whether the active release of memory variables is valuable.
Original experiment code:
<Script language = vbscript runat = server> Dim temp1, temp2'Temp1 = space (1024*1024*50) '50 MB For I = 0 to 5000000 'latency Next 'Temp1 = "" 'Switch variable 'Temp2 = space (1024*1024*50) '50 MB For I = 0 to 5000000 'latency Next Response. write "<meta http-equiv = 'refresh' content = '4; url = http: // localhost/memory_test.ASP '>" </Script> |
Memory Change 1:
Explanation: the changes in the CPU waveform are caused by automatic page refresh. Don't worry! We only need to observe the changes in the memory line. This is the original state, and the memory line remains unchanged horizontally.
Okay. The following experiment is officially started:
Step 1:
In the original code
'Temp1 = space (1024*1024*50) '50 MB
Remove the comment 'and change it
Temp1 = space (1024*1024*50) '50mb
<Script language = vbscript runat = server> Dim temp1, temp2Temp1 = space (1024*1024*50) '50mb For I = 0 to 5000000 'latency Next 'Temp1 = "" 'Switch variable 'Temp2 = space (1024*1024*50) '50 MB For I = 0 to 5000000 'latency Next Response. write "<meta http-equiv = 'refresh' content = '4; url = http: // localhost/memory_test.ASP '>" </Script> |
Then observe the memory changes for a period of time
Memory change 2:
Result: A square wave occurs in the memory.
Step 2:
Then
'Temp2 = space (1024*1024*50) '50 MB
Remove the comment 'and change it
Temp2 = space (1024*1024*50) '50mb
<Script language = vbscript runat = server> Dim temp1, temp2Temp1 = 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 3:
Result: The square wave is a step higher than the original one.
Step 3:
Then
'Temp1 = "" 'Switch variable
Remove the comment 'and change it
Temp1 = "" 'Switch variable
<Script language = vbscript runat = server> Dim temp1, temp2Temp1 = 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> |
Check whether the memory space occupied by the first variable can be released.
Memory change 4:
Result: Obviously, the Second Wave Front disappeared and it seems that the release was successful.
Step 4:
We first restored the code to the original code. After the memory is stabilized, we can perform the first three steps quickly to compare the memory changes in the same one.
Memory change 5:
Result: we can clearly see the differences between the three cases. The execution time and memory usage of the non-lun mode are better than those of the non-passive mode.
Step 5:
The code in step 3 puts
Temp1 = "" 'Switch variable
Temp2 = space (1024*1024*50) '50mb
Change
'Temp1 = "" 'Switch variable
Temp1 = space (1024*1024*50) '50mb
<Script language = vbscript runat = server> Dim temp1, temp2Temp1 = 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 6:
Result: Let's take a look at the next step to draw a conclusion.
Step 6:
Set
'Temp1 = "" 'Switch variable
Change
Temp1 = "" 'Switch variable
<Script language = vbscript runat = server> Dim temp1, temp2Temp1 = 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> |
Check whether the results are different.
Memory change 7:
Result: with the same variable name, even if the value is re-assigned, the occupied space cannot be released or replaced (6). When the program is passively released, the usage time is also slower than that of manual operations (both 6 and 7 ).
Next
Temp1 = "" 'Switch variable
Temp1 = space (1024*1024*50) '50mb
Change the positions of the two sentences
Temp1 = space (1024*1024*50) '50mb
Temp1 = "" 'Switch variable
<Script language = vbscript runat = server> Dim temp1, temp2Temp1 = 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> |
The last 8:
Result: The active release takes less time than the passive release time (peak)
Experiment conclusion:
It is helpful to actively release the memory. Some people do not say that the memory can be released only after the page ends, or the memory will be automatically released after the program ends, it can also be manually controlled during execution. In particular, when a program needs to call several large variables, releasing useless variables as soon as possible can not only reduce the burden on the server, but also speed up program running.
If the experiment process or conclusion is incorrect, please correct it.
Finally, the results of release with "", empty or null are basically the same. If you are interested, try it yourself. As to which variable is used to release variables is more formal or efficient, I cannot determine it in this experiment. I hope you can give me some advice.
(Source: Viphot)