Web tutorials: About IE memory leaks and JavaScript memory release

Source: Internet
Author: User
Tags reference return variable
Javascript| Tutorials | Web page

Recently to do a company's business system, the company requirements can be as close to C/s as possible, that is, such as C/S, click the text box can pop up the relevant content of the project, select Input.

I use a pop-up window, and then double-click the selected item in the child window to return the selected value to the parent form.

After the system is finished, in the process of customer use, because the customer is using 512m memory configuration, so after opening the 30--40 form, ie virtual memory footprint reached nearly 200m, so that the system slowed down, JavaScript running also slowed.

I use Task Manager, open a pop-up window, ie memory to increase 1-3m, and then close the window, sometimes the memory does not release, sometimes release dozens of K. It appears that the problem is in the memory release.

Then, according to the memory release of this idea, search to find a way to solve this problem. I found a JavaScript non-public function collectgarbage, which is used for memory release. I set all of my defined javasctip variables to null before the end of all pop-ups and call the CollectGarbage function.

Setting a variable to Null,javascript in JavaScript does not release memory, and the next time you define a variable, it overwrites the memory in which the variable resides. If you do not set the variable to Null,javascript again, a new memory space is opened.

After using the above processing, open the window again, ie memory each time or increase 1-3m, but after the window is closed, IE will release a certain amount of memory in 500k to 2m. Played a certain role.
Because I use third party controls on the page, the memory in JavaScript in third party controls is not controlled by me.

  Example of a method for 1.javascript memory release

Even set the parameters of all the superior functions to null and use CollectGarbage to free the memory.

Example

<script>
32M
function AllocMem ()
{
var str= "12345678";
for (Var i=3;i<24;i++)
STR+=STR;
return str;
}
function A (a)
{
A=null;
return R;
function R ()
{
}
}
var f=a (AllocMem ());
Alert (1);
CollectGarbage ();
Obviously, it's been released.
R=null;
Alert (2);
CollectGarbage ();
</script>

The rules for memory release (script layer) are well understood.
(Per-level menu assignment?) M's memory. To the task Manager to see the situation

Note:
CollectGarbage () usually comes out of memory at the core, because it is called when IE or NS programs end. That's safe.

Description
1 If you keep the object's reference in the window in another window, the memory is not released even if you close the window
  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      when   the   process   is   terminated  

2 worse, if you keep a DOM object reference, close the object's window, IE will crash, report a memory error (or request, reboot)

I would say this looks like a bug and you might want to the Microsoft



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.