久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='wcPHN'></tfoot>
      <bdo id='wcPHN'></bdo><ul id='wcPHN'></ul>

    <small id='wcPHN'></small><noframes id='wcPHN'>

  1. <i id='wcPHN'><tr id='wcPHN'><dt id='wcPHN'><q id='wcPHN'><span id='wcPHN'><b id='wcPHN'><form id='wcPHN'><ins id='wcPHN'></ins><ul id='wcPHN'></ul><sub id='wcPHN'></sub></form><legend id='wcPHN'></legend><bdo id='wcPHN'><pre id='wcPHN'><center id='wcPHN'></center></pre></bdo></b><th id='wcPHN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wcPHN'><tfoot id='wcPHN'></tfoot><dl id='wcPHN'><fieldset id='wcPHN'></fieldset></dl></div>

      <legend id='wcPHN'><style id='wcPHN'><dir id='wcPHN'><q id='wcPHN'></q></dir></style></legend>

      垃圾回收在 JavaScript 中是如何工作的?

      How does garbage collection work in JavaScript?(垃圾回收在 JavaScript 中是如何工作的?)

          <tbody id='Vx197'></tbody>
          <tfoot id='Vx197'></tfoot>

          <legend id='Vx197'><style id='Vx197'><dir id='Vx197'><q id='Vx197'></q></dir></style></legend>
            <bdo id='Vx197'></bdo><ul id='Vx197'></ul>

          • <small id='Vx197'></small><noframes id='Vx197'>

              • <i id='Vx197'><tr id='Vx197'><dt id='Vx197'><q id='Vx197'><span id='Vx197'><b id='Vx197'><form id='Vx197'><ins id='Vx197'></ins><ul id='Vx197'></ul><sub id='Vx197'></sub></form><legend id='Vx197'></legend><bdo id='Vx197'><pre id='Vx197'><center id='Vx197'></center></pre></bdo></b><th id='Vx197'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Vx197'><tfoot id='Vx197'></tfoot><dl id='Vx197'><fieldset id='Vx197'></fieldset></dl></div>

              • 本文介紹了垃圾回收在 JavaScript 中是如何工作的?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                垃圾回收在 JavaScript 中是如何工作的?它類似于 .NET 垃圾收集嗎?是不是因為 VBScript 中垃圾回收的實現很糟糕,人們才避免使用它,而偏愛 JavaScript 作為他們的標準客戶端語言?

                解決方案

                垃圾回收是如何工作的?

                簡短的回答是:當一塊內存(比如一個對象)不再可訪問時,它就有資格被回收.何時、如何或是否回收完全取決于實現,不同的實現方式不同.但在語言層面,它是自動的.

                例如:

                函數 foo() {變量欄;酒吧 = 新的真正大規模對象();bar.someCall();}

                foo 返回時,bar 指向的對象自動可用于垃圾回收,因為沒有任何東西可以引用它.

                對比:

                函數 foo() {變量欄;酒吧 = 新的真正大規模對象();bar.someCall();返回欄;}//其他地方var b = foo();

                ...現在對該對象的引用在調用中仍然存在,并且一直存在,直到/除非調用者將其他內容分配給 bb 超出范圍.

                同時對比:

                函數 foo() {變量欄;酒吧 = 新的真正大規模對象();bar.someCall();設置超時(函數(){alert("三秒過去了");}, 3000);}

                這里,即使在foo返回后,定時器機制也有對定時器回調的引用,而定時器回調 —閉包 —對創建它的上下文有一個引用,該上下文又包含 bar 變量.因此,理論上,當 foo 返回時,bar 所指的內容不能立即用于垃圾回收.相反,它會一直保留到計時器觸發并釋放其對回調的引用,從而使回調及其引用的上下文符合 GC 條件.(在實踐中,現代 JavaScript 引擎可以并且確實優化了閉包.例如,在上面,靜態分析顯示回調不引用 bar,并且不包含任何 evalnew Function 代碼可能會在運行時動態引用它,因此 JavaScript 引擎可以安全地將 bar 排除在函數引用的上下文之外,從而使它所指的東西有資格獲得 GC — 和現代的).(在這篇文章中了解更多關于閉包的信息.)p>

                JavaScript 在清理循環引用時沒有問題,順便說一句,例如:

                函數 foo() {變量 a, b;一個 = {};b = {};b.refa = a;a.refb = b;}

                foo 返回時,a 指的是 b 并且反之亦然的事實不是問題.由于沒有其他內容涉及它們中的任何一個,因此它們都可以被清理.在 IE 上,如果其中一個對象是主機提供的對象(例如 DOM 元素或通過 new ActiveXObject 創建的東西)而不是 JavaScript 對象,則這為真.(例如,如果您將 JavaScript 對象引用放在 DOM 元素上,并且 JavaScript 對象引用回 DOM 元素,即使沒有人引用它們中的任何一個,它們也會在內存中相互保存.)但這是一個 IE bug問題,不是 JavaScript 的問題.

                回復:

                <塊引用>

                是因為 vbscript GC 不好,人們將 javascript 作為他們的標準客戶端 api 嗎?

                JavaScript 是原始客戶端網絡腳本語言.VBScript 只是在后來微軟推出瀏覽器時才出現,并且只在微軟瀏覽器中得到支持.如果您想使用最廣泛的瀏覽器,JavaScript 曾經是并且現在是唯一的客戶端腳本游戲.<subjective>它也是經典 VBScript 語言的八倍.;-) </主觀的>

                How does garbage collection work in JavaScript? Is it similar to .NET garbage collection? And is it because the implementation of garbage collection in VBScript is bad that people avoided it and established a preference for JavaScript as their standard client-side language?

                解決方案

                How does garbage collection work?

                The short answer is: When a block of memory (an object, say) is no longer reachable, it is eligible to be reclaimed. When, how, or whether it is reclaimed is entirely up to the implementation, and different implementations do it differently. But at a language level, it's automatic.

                For example:

                function foo() {
                    var bar;
                
                    bar = new ReallyMassiveObject();
                    bar.someCall();
                }
                

                When foo returns, the object bar points to is automatically available for garbage collection because there is nothing left that has a reference to it.

                Contrast with:

                function foo() {
                    var bar;
                
                    bar = new ReallyMassiveObject();
                    bar.someCall();
                    return bar;
                }
                // elsewhere
                var b = foo();
                

                ...now a reference to the object survives the call, and persists until/unless the caller assigns something else to b or b goes out of scope.

                Also contrast with:

                function foo() {
                    var bar;
                
                    bar = new ReallyMassiveObject();
                    bar.someCall();
                    setTimeout(function() {
                        alert("Three seconds have passed");
                    }, 3000);
                }
                

                Here, even after foo returns, the timer mechanism has a reference to the timer callback, and the timer callback — a closure — has a reference to the context where it was created, which in turn contains the bar variable. As a result, in theory, what bar refers to isn't available for garbage collection immediately when foo returns. Instead, it's kept around until the timer fires and releases its reference to the callback, making the callback and the context it refers to eligible for GC. (In practice, modern JavaScript engines can and do optimize closures where they can. For instance, in the above, static analysis shows the callback doesn't refer to bar, and doesn't contain any eval or new Function code that might refer to it dynamically at runtime, so the JavaScript engine can safely leave bar out of the context the function refers to, thus making what it refers to eligible for GC — and modern ones do). (More about closures in this article.)

                JavaScript has no problem handling cleaning up circular references, btw, so for instance:

                function foo() {
                    var a, b;
                
                    a = {};
                    b = {};
                    b.refa = a;
                    a.refb = b;
                }
                

                When foo returns, the fact that a is referring to b and vice-versa isn't a problem. Since nothing else refers to either of them, they can both get cleaned up. On IE, this is not true if one of the objects is a host-provided object (such as a DOM element or something created via new ActiveXObject) instead of a JavaScript object. (So for instance, if you put a JavaScript object reference on a DOM element and the JavaScript object refers back to the DOM element, they keep each other in memory even when no one is referencing either of them.) But that's an IE bugissue, not a JavaScript thing.

                Re:

                is it because the vbscript GC is bad that people reverted to javascript as their standard client side api?

                JavaScript was the original client-side web scripting language. VBScript only came later, when Microsoft came out with a browser, and was only ever supported in Microsoft browsers. JavaScript was and is the only client-side scripting game in town if you want to work with the broadest range of browsers. <subjective>It's also about eight times the language classic VBScript ever was. ;-) </subjective>

                這篇關于垃圾回收在 JavaScript 中是如何工作的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                <legend id='KQf7k'><style id='KQf7k'><dir id='KQf7k'><q id='KQf7k'></q></dir></style></legend>
                  <bdo id='KQf7k'></bdo><ul id='KQf7k'></ul>

                      <tbody id='KQf7k'></tbody>
                      <i id='KQf7k'><tr id='KQf7k'><dt id='KQf7k'><q id='KQf7k'><span id='KQf7k'><b id='KQf7k'><form id='KQf7k'><ins id='KQf7k'></ins><ul id='KQf7k'></ul><sub id='KQf7k'></sub></form><legend id='KQf7k'></legend><bdo id='KQf7k'><pre id='KQf7k'><center id='KQf7k'></center></pre></bdo></b><th id='KQf7k'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='KQf7k'><tfoot id='KQf7k'></tfoot><dl id='KQf7k'><fieldset id='KQf7k'></fieldset></dl></div>

                      <small id='KQf7k'></small><noframes id='KQf7k'>

                      1. <tfoot id='KQf7k'></tfoot>
                        1. 主站蜘蛛池模板: 激情 婷婷| h视频免费在线观看 | 久久青 | 久久www免费人成看片高清 | 一区二区三区在线 | 精品一区国产 | 91精品久久久久久久久久入口 | 成人在线一区二区 | 国产视频1区 | 中文字字幕一区二区三区四区五区 | 久久久久久久一区二区三区 | 成人午夜在线观看 | 精品91| 日韩中文字幕在线观看视频 | 精品久久久久久亚洲综合网站 | 国产精品视频免费观看 | 一级黄色短片 | 免费污视频 | 在线视频中文字幕 | 成人在线视频网 | 亚洲成人免费视频在线观看 | 日韩视频精品在线 | 丁香婷婷综合激情五月色 | 国产免费一区二区三区 | avav在线看| 日本一区二区在线视频 | 免费国产黄 | 欧美成人一区二区 | 久久高清亚洲 | 国产 日韩 欧美 在线 | 欧美一级片a | 国产精品无码久久久久 | 午夜影院在线播放 | 日本黄色高清视频 | 播放一级黄色片 | 国产一区二区三区四区 | 国产成人精品一区二区三区网站观看 | 中文字幕一区二区三区四区五区 | 一区二区免费视频 | 午夜久久久 | 久久精品一区二区三区四区 |