Memory leak on IE and the JavaScript memory release



Recently become a company's business systems, companies require to as much as possible and c / s approximation, that is, if c / s, like, click on the text box to pop up the relevant content of this item, select input.

I use the pop-up window, and then double-click the selected item in the child window, the selected value back to the parent form. After the system finished, in the process of customers, because customers are using 512m of memory configurations, so in the Open 30 - 40 after the form, ie the amount of virtual memory footprint of nearly 200m, which makes the system slow , javascript running too slow. After the google search, I only know that may be due to a memory leak caused by ie.

Use Task Manager to open a pop-up window, ie to increase the memory to 1-3m, and then close the window, sometimes the memory is not released, had only the release of dozens of k. It seems the problem lies in the memory release above.

Then the release of this train of thought by the memory, the search to find ways to carry out the problem. I found a javascript function not open CollectGarbage, this function is used for memory release. I pop in all of their own before the end of all the variables defined javasctip set to null, and call CollectGarbage function.

javascript in the variable set to null, javascript will not release memory, when the next re-definition of variables, this variable will overwrite the memory location. If not set to null, javascript definition of variables again, it will open up a new memory space.

After using the above address, once again open the window, ie each memory or increase the 1-3m, but after closing the window, then ie will release a certain amount of memory in the 500k to 2m. Played a certain role.

Since I use a third party in the page's control, third-party control in the javascript in the memory is how to manage, it is not for me to control the.

1.javascript memory release method of sample

All the higher functions of the parameters even if set to null, and use CollectGarbage to free memory.

Example





Which the rules for release of memory (the script layer) has to understand very thoroughly.

(Distribution of each layer menu? M of memory. Facing the task manager only to see the situation)

Note:

CollectGarbage () is usually introduced in the core memory, because that is the end of IE or NS procedures will be called when. It is safe.

Description:

1) If you keep in another window in the window of the object of reference, even to close the window, memory is not released

2) Even worse, if you keep is a DOM object of reference, to close the object where the window, IE may crash, reporting a memory error (or required to re-start)