亚洲欧美精品沙发,日韩在线精品视频,亚洲Av每日更新在线观看,亚洲国产另类一区在线5

<pre id="hdphd"></pre>

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

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

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

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

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

        Hedger Wang 在國(guó)內(nèi) blog 上得到的方法:使用 try … finally 結(jié)構(gòu)來(lái)使對(duì)象最終為 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....

        對(duì)于 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....

        可能大家有疑問(wèn): finally 是如何解析的呢?

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

        例如:

        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