Home > Article > Web Front-end > About ie memory leaks and javascript memory release
Recently I am working on a company's business system. The company requires it to be as close to c/s as possible, that is, just like c/s, click on the text box to pop up the relevant content of this project for selection and input.
I used a pop-up window, then double-clicked the selected item in the child window and returned the selected value to the parent form.
After the system is completed, during the customer's use, since the customer uses a 512m memory configuration, after opening 30--40 forms, the virtual memory usage of IE reaches nearly 200m, thus making the system Slow, the running of javascript also slows down.
After searching on Google, I found out that it might be caused by a memory leak in IE. For details, please refer to relevant articles in www.cnblogs.com.
I use the task manager and open a pop-up window, and the memory of IE increases by 1-3m, and then I close the window. Sometimes the memory is not released, and sometimes it is only released for tens of kilobytes. It seems that the problem lies in memory release.释 Then release the idea of memory and search for search methods to solve this problem. I found an undisclosed JavaScript function CollectGarbage, which is used to release memory. I set all the self-defined javasctip variables to null before all pop-up windows end, and call the CollectGarbage function.
If you set a variable to null in JavaScript, JavaScript will not release the memory. When the variable is defined again next time, the memory where the variable is located will be overwritten. If it is not set to null, JavaScript will open up a new memory space when defining the variable again.
After using the above processing, when you open the window again, the memory of IE still increases by 1-3m each time, but after closing the window, IE will release a certain amount of memory ranging from 500k to 2m. Played a certain role.
Since I use third-party controls in the page, how the memory in the JavaScript in the third-party controls is managed is not under my control. V a 1.javaScript memory release method Example
The parameters of all superior functions are set to NULL, and the collectgarbage is used to release the memory.
Example
Note:
1) If you keep the reference of the object in the window in another window, even if you close the window, the memory will not be released
As you might know, windows opened with window.open() may share a process with its opener (_blank or _new window may not). That is, even if you see those two windows on the desktop, if you look at the process table in the Task Manager, you may only see one IEXPLORE.EXE running. Memory may only be released when the process is terminated
2) What’s worse is that if you keep a reference to a DOM object and close the window where the object is located, IE will crash and report a memory error (or require a restart)
I would say this looks like a bug, you might want to report to Microsoft
Please pay attention to the PHP Chinese website (www.php.cn) for more related articles!