Resolution of memory leaks when using jquery to reset an iframe address under IE

Source: Internet
Author: User

There is an IFRAME in the page:

<iframe src= ' a.html ' ></iframe><button> test iframe leaks </button>

The contents of a.html are as follows:

<! doctype html>

B.html content is as follows:

<! DOCTYPE html>

Online transmission, the following wording to reduce memory leaks:

var framedom = $ (' iframe:eq (0) ') [0]; var framewin = Framedom.contentwindow;       try{FrameWin.document.write (");  FrameWin.document.clear ();  }catch (e) {}; FRAMEDOM.SRC = ' b.html ';

So what's the effect?

One: Set the URL directly

var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' Click ', function () {&NBSP;&NBSP;IF (flag) {   var framedom = $ (' iframe:eq (0) ') [0];    var frameWin = frameDom.contentWindow;   /*    Try{     framewin.document.write (');      FrameWin.document.clear ();        }catch (e) {};        */      frameDom.src =  ' b.html ';    flag  = false;  }else{   var framedom = $ (' iframe:eq (0) ') [0];    var frameWin = frameDom.contentWindow;   /*    Try{     framewin.document.write (');      FrameWin.document.clear ();      &nBsp; }catch (e) {};       */       framedom.src =  ' a.html ';    flag = true;  }  //$ (' # Console '). Append (flag ?  ' Switch to a.html ': ' Switch to b.html ');  });

Use the Sieve test: #leaks增加28左右 each time you switch.

Two: According to the network to send the wording

<script> var flag = true; var framedom = $ (' iframe:eq (0) ') [0];  $ (' button '). On (' click ', Function () {&NBSP;&NBSP;IF (flag) {       var  framedom = $ (' iframe:eq (0) ') [0];       var framewin  = frameDom.contentWindow;       try{             framewin.document.write (');             framewin.document.clear ();         }catch (e) {};        framedom.src =  ' b.html ';        flag = false;  }else{        var framedom = $ (' iframe:eq (0) ') [0];       var  framewin = framedom.contentwindow;       try{            framewin.document.write (');            framewin.document.clear ();         }catch (e) {};         frameDom.src =  ' a.html ';        flag  = true;  }  //$ (' #console '). Append (flag ?  ' Switch to a.html ': ' Switch to b.html ');  });</script>

Use the Sieve test: #leaks增加28左右 each time you switch. There's no difference between writing and writing.

Three:

var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' Click ', function () {&NBSP;&NBSP;IF (flag) {   /*   try{      framedom.contentwindow.document.write (');      FrameDom.contentWindow.document.clear ();      framedom.contentwindow.close ();        }catch (e) {};      */       $ (' iframe:eq (0) '). Remove ();       $ (' body '). Append ("<iframe  Src= ' b.html ' ></iframe> ');   flag = false;  }else{    /*   try{     framedom.contentwindow.document.write (');      framedom.contentwindow.document.clear ();      FrameDom.contentWindow.close ();        }catch (E) {};      */      $ (' iframe:eq (0) '). Remove ( );       $ (' body '). Append ("<iframe src= ' a.html ' ></iframe>");    flag = true;  } });

Using the Sieve test: #leaks平均为 3, which is significantly different from the first two

Four: Notice that the three comments in the code of a paragraph, remove the comment?

var flag = true; var framedom = $ (' iframe:eq (0) ') [0]; $ (' button '). On (' Click ', function () {&NBSP;&NBSP;IF (flag) {      try{      FrameDom.contentWindow.document.write (");      framedom.contentwindow.document.clear ( );      framedom.contentwindow.close ();        } catch (E) {};            $ (' iframe:eq (0) '). Remove ();       $ (' body '). Append ("<iframe src= ' b.html ' ></iframe>");    flag = false;  }else{      try{      framedom.contentwindow.document.write (');      FrameDom.contentWindow.document.clear ();      framedom.contentwindow.close ();        }catch (e) {};            $ (' iframe:eq (0) '). Remove ();       $ (' body '). Append ("<iframe src= ' a.html ' ></iframe>");    flag = true;  } });

This writing and writing 3 does not differ significantly, each switch #leaks still increase by about 3

So it can be concluded that the best solution to resetting the IFRAME address memory leak is to kill it and add one!

The internet doesn't have to be reliable.

Note: The native test environment is WIN7 x64 IE9

Resolution of memory leaks when using jquery to reset an iframe address under IE

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.