An experimental report on the release of ASP memory

Source: Internet
Author: User
Tags variables
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:
CPU waveform changes are caused by automatic page refresh, do not care! All we have to observe is a change in the memory line. This is the original state where the memory line remains unchanged.

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

And then watch the memory change for some time.

Memory Change screenshot 2:


Results:
The square wave begins to appear in memory.

Step Two:

And then put
' Temp2 = Space (1024*1024*50) ' 50MB
The previous annotation number ' removed, changed to
Temp2 = Space (1024*1024*50) ' 50MB

Memory Change screenshot 3:


Results:

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

See if you can free the memory space occupied by the first variable

Memory Change screenshot 4:


Results:
It was clear that the second wave-front was gone, and it appeared 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. No 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

Memory Change screenshot 6:


Results:
Look at the next step before you get to the conclusion.

Sixth step:

Put
' temp1= ' "' Switch variable

Change into
temp1= "" ' Switch variable


See if the results will be different.

Memory Change screenshot 7:


Results:
With the same variable name, even if the value again, the original occupied space can not be released or replaced, and so the program passive release, the use of time than manual slow.

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

After the screenshot 8:


Results:
It can be seen that the active release takes less time than the passive.

Experimental conclusion:
Active to free memory is useful, not some people say to wait for the end of the page can be released, or just wait until the end of the program is automatically released, but in the implementation process can also be artificially controlled. In particular, when you need to call a few large variables in the program, release the useless variables as soon as possible, 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 do their own hands-on comparison. As to the use of which to release the variable more formal or more efficient, I can not judge in the experiment, I would like to know friends to teach.

 

Attachment: Another less relevant experiment

Whether there is any difference in content within the <%%> (including annotations)

Experimental code:

<meta http-equiv= ' refresh ' content= ' 4;url=http://localhost/memory_test.asp ' >
<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


</script>
<%
'
%>

 

Experimental results:

No content in 1.<%%>, memory does not change

2.<%%> only one ' number, memory starts to change

Before and after the change Figure 9:



Results:
<% has nothing to do with <script Language=vbscript runat=server>, but it seems as long as there is content in <%%> the <script ru Code inside the nat=server></script>. But just replace <script language=vbscript runat=server></script> with <%%> Executes the code within the <%%>, so pay attention to the mix of the two later.

Also, this kind of page script in <script language=vbscript>, unless the page is turned off, the variables used are not automatically purged like the ASP. Can be verified from the following code:

<script language=vbscript>
Dim Temp
temp = Space (1024*1024*50) ' 50MB
' temp = '
</script>

Note that the memory footprint changes before and after the annotation number is removed, no more screenshots.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.