国产宅男网站在线|亚洲A级性爱免费视频|亚洲中精品级在线|午夜福利AA毛

  • <dd id="gf5jf"><th id="gf5jf"></th></dd>

    <cite id="gf5jf"><label id="gf5jf"></label></cite>
  • <div id="gf5jf"><listing id="gf5jf"></listing></div>
    學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 電腦硬件知識(shí) > 內(nèi)存知識(shí) > IE6內(nèi)存泄漏怎么解決

    IE6內(nèi)存泄漏怎么解決

    時(shí)間: 孫勝龍652 分享

    IE6內(nèi)存泄漏怎么解決

      大家都知道,內(nèi)存是電腦必不可少的一個(gè)硬件,所以說,關(guān)于內(nèi)存會(huì)有各種各樣的問題,學(xué)習(xí)啦小編就在這里給大家介紹IE6內(nèi)存泄漏怎么解決。

      Hedger Wang 在國內(nèi) blog 上得到的方法:使用 try … finally 結(jié)構(gòu)來使對象最終為 null ,以阻止內(nèi)存泄露。

      其中舉了個(gè)例子:

      function createButton() {

      var obj = document.createElement("button");

      obj.innerHTML = "click me";

      obj.onclick = function() {

      //handle onclick

      }

      obj.onmouseover = function() {

      //handle onmouseover

      }

      return obj;//return a object which has memory leak problem in IE6

      }

      var dButton = document.getElementById("d1").appendChild(createButton());

      //skipped....

      對于 IE6 中,引起內(nèi)存泄露的原因,可看《Understanding and Solving Internet Explorer Leak Patterns》一文。

      上面的例子,應(yīng)該屬于上文中的 “Closures”原因。

      再看下用 try … finally 的解決方法:

      /**

      * Use the try ... finally statement to resolve the memory leak issue

      */

      function createButton() {

      var obj = document.createElement("button");

      obj.innerHTML = "click me";

      obj.onclick = function() {

      //handle onclick

      }

      obj.onmouseover = function() {

      //handle onmouseover

      }

      //this helps to fix the memory leak issue

      try {

      return obj;

      } finally {

      obj = null;

      }

      }

      var dButton = document.getElementById("d1").appendChild(createButton());

      //skipped....

      可能大家有疑問: finally 是如何解析的呢?

      答案是:先執(zhí)行 try 語句再執(zhí)行 finally 語句。

      例如:

      function foo() {

      var x = 0;

      try {

      return print("call return " ( x));

      } finally {

      print("call finally " ( x));

      }

      }

      print('before');

      print(foo());

      print('after');

      返回的結(jié)果為:

      print » before

      print » call return 1

      print » call finally 2

      print » true

      print » after

    297648