A summary of the research on IE memory leak and can't recycle

Source: Internet
Author: User

A summary of the research of IE memory leak and can't recycle one, memory leaks
Before I did see a lot of information, but the eldest brother's words can be a finishing touch, not flatter him, and suddenly opened the two veins of my governor, please see:
Trarck wrote
The reason of memory leakage under IE is circular reference, ie garbage collector can't handle this kind of reference well.
A leaked circular reference is generated, with only isolated DOM objects (out of the DOM tree).
A circular reference between orphaned DOM objects, an orphaned DOM object and a circular reference to a JS object.
Why is it an isolated DOM object? When you leave the page (refresh, jump) deletes the entire DOM tree, the object on the DOM tree is deleted, even if there is a circular reference, it is interrupted at this time.
The isolated DOM objects are: one, created with JS but not added to the DOM tree. Second, removed from the DOM tree.
So avoid leaks, and try not to allow such DOM objects to be generated.
Sometimes such objects are unavoidable, so do not let such an image produce circular references.
The most common circular reference is generated by closures, and the variables (including parameters) in the execution environment reference the DOM object.
After reading this passage, I will only fear to imitate the example of my immediate self-created a new example.
Example 1:
  1. <input type="button" value= "Leak" id= "Leak" onclick= "location.reload ();" />
  2. <script type="Text/javascript" ><!--
  3. (function () {
  4. var test=$ (' <div/> ') [0];
  5. Test.onclick=function () {};
  6. var s=[];
  7. For (var i=0;i<10000;i++) {
  8. S.push (' aaaa ');
  9. }
  10. Test.expan=s.join (");
  11. //$ (' body '). Append (test);
  12. ///Isolated DOM elements will leak
  13. })();
  14. --></script>

Special case: IFRAME
The Test tool is: sIEve-0.0.8
Refreshes the page in the IFRAME, with a lot of leaks in the page, one more time per brush, but all the leaks disappear when the parent page is refreshed last.
And the IFRAME is proposed to test (refresh) alone, no leakage.

Second, memory recovery
1. Clear global references. The reason is simple, as long as the global reference exists in the browser cannot release the corresponding object, because in the life cycle of the reference, the object may be called at any time.
  1. <input type="button" value="to GC" onclick="togc ()" />
  2. <script type="Text/javascript"><!--
  3. function togc () {
  4. g.s=null;
  5. }
  6. var g={};
  7. G.s=[];
  8. for (Var i=0;i<100;i++) {
  9. G.s.push ($ ('<div /> ') [0]);
  10. }
  11. --></script>

If you do not click the To GC button, the created Div will never be released until the page unload.
2, each browser different memory release mechanism
A normal (leak-free) page, when it unload (for example, href points to About:blank), the memory release is not the same in different browsers. Did a test, use a famous e-commerce website as the test object.
IE7: There will be no significant release, even if 1 hours, the memory is still high, the minimized window will be released to a few m level.
FireFox3: Not released at any time, no method has been found (except, of course, close the window).
Chrome6: Release now.

A summary of the research on IE memory leak and can't recycle

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.