Memory leakage of ie and the release of javascript memory

Source: Internet
Author: User
Tags memory usage
Recently, as a company's business system, the company requires that it be as close as possible to c/s, that is, like c/s. Click the text box to bring up the relevant content of this project, select Input.
I used the pop-up window. In the subwindow, double-click the selected project and return the selected value to the parent form.
After the system is complete, the customer uses the M memory configuration, so after opening 30-40 forms, the virtual memory usage of ie reaches nearly 200 MB, which slows down the system and the javascript operation.

After a google search, I realized that it may be caused by the memory leakage of ie.

I use the task manager to open a pop-up window. The ie memory is increased by 1-3 MB, and then the window is closed. Sometimes the memory is not released, and sometimes dozens of k is released. It seems that the problem lies in the memory release.

Then, based on the idea of releasing memory, search and find methods to solve the problem. I found an undisclosed javascript function CollectGarbage, which is used to release the memory. Before the completion of all the pop-up windows, I set all the variables of the custom javasp p to null and call the CollectGarbage function.

In javascript, the variable is set to null, and javascript does not release the memory. When the variable is defined again, the memory where the variable is located will be overwritten. If it is not set to null, a new memory space will be opened when javascript defines the variable again.

After the above processing is used, open the window again. The ie memory is increased by 1-3 MB each time, but after closing the window, then, ie will release a certain amount of data that exists between KB and 2 MB. Has played a certain role.
Since I use third-party controls on the page, I do not control the memory in javascript in the third-party controls.

1. Example of how to release javascript memory

Set the parameters of all upper-level functions to null and use CollectGarbage to release the memory.


Example
<Script>
   
// 32 M
Function AllocMem ()
  {  
Var str = "12345678 ";
For (var I = 3; I <24; I ++)
Str + = str;
Return str;
  }  
   
Function A ()
  {  
A = null;
Return r;
Function r ()
  {  
  }  
  }  
   
   
Var f = A (AllocMem ());
Alert (1 );
CollectGarbage ();
// Obviously, it has been released.
R = null;
Alert (2 );
CollectGarbage ();
   
</Script>
   
----------
The memory release rules (script layer) are well understood.

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.