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

<legend id='49dPn'><style id='49dPn'><dir id='49dPn'><q id='49dPn'></q></dir></style></legend>

    1. <tfoot id='49dPn'></tfoot>

    2. <small id='49dPn'></small><noframes id='49dPn'>

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

        • <bdo id='49dPn'></bdo><ul id='49dPn'></ul>

        Javascript中同一變量上的“new"沒有“delete&qu

        `new` without `delete` on same variable in Javascript(Javascript中同一變量上的“new沒有“delete)

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

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

                  本文介紹了Javascript中同一變量上的“new"沒有“delete"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這樣可以嗎?:

                  function mygetTime()
                  {
                      var d = new Date();
                      return(d.getTime());
                  }
                  
                  function wasteSomeMemory()
                  {
                      var temp;
                      for(var count = 0; count < 1000000; count += 1)
                      {
                          temp = mygetTime();
                      }
                  }
                  

                  調用 wasteSomeMemory() 會導致內存泄漏嗎?

                  Will calling wasteSomeMemory() cause a memory leak?

                  這個呢:

                  function wasteSomeMemory2()
                  {
                      var temp;
                      for(var count = 0; count < 1000000; count += 1)
                      {
                          temp = new Date();
                      }
                  }
                  

                  調用 wasteSomeMemory2() 會導致內存泄漏嗎?我應該在 for 循環的末尾使用 delete temp; 嗎?

                  Will calling wasteSomeMemory2() cause a memory leak? Should I use delete temp; at the end of the for-loop?

                  function wasteSomeMemory2()
                  {
                      var temp;
                      for(var count = 0; count < 1000000; count += 1)
                      {
                          temp = new Date();
                          delete temp;
                      }
                  }
                  

                  推薦答案

                  newdelete 在 JavaScript 中彼此沒有任何關系(盡管它們與其他語言中完全不同的結構).不要擔心在沒有明確清理的情況下創建對象(new),這是垃圾收集器的工作.

                  new and delete have nothing whatsoever to do with each other in JavaScript (despite their confusing similarity to completely different constructs in other languages). Don't worry about creating objects (new) without explicitly cleaning them up, that's the garbage collector's job.

                  new 用于通過構造函數創建對象.另一方面,delete 用于從對象中刪除屬性.它與從內存中刪除對象無關,除了作為副作用(例如,如果對該對象的唯一未完成引用來自您刪除的屬性).

                  new is for creating objects via constructor functions. delete, on the other hand, is for removing properties from objects. It has nothing to do with removing an object from memory, other than as a side effect (e.g., if the only outstanding reference to that object was from the property that you removed).

                  delete的正確使用示例:

                  var obj = {};
                  obj.foo = "bar"; // Now `obj` has a property called `foo`
                  delete obj.foo;  // Now it doesn't
                  

                  您的 getmyTime 功能非常好.Date 對象將有資格在函數返回后立即被回收(是否被回收完全取決于實現).它不會導致內存泄漏,除非有錯誤的實現.

                  Your getmyTime function is perfectly fine. The Date object will become eligible to be reclaimed immediately upon function return (whether it is reclaimed is completely down to the implementation). It does not cause a memory leak, except on a buggy implementation.

                  您的 wasteSomeMemory2 同樣不會導致內存泄漏,實際上您不能調用 delete temp; —你只能刪除屬性,不能刪除變量.

                  Your wasteSomeMemory2 similarly doesn't cause a memory leak, and in fact you can't call delete temp; — you can only delete properties, not vars.

                  次您必須幫助垃圾收集器,但這些通常(根據我的經驗)與對象屬性無關,因此不涉及 delete.它們只有在您創建函數實例時才會真正出現(如果您正在設置事件處理程序或計時器函數等,這很常見).例如,考慮:

                  There are times when you have to help the garbage collector out, but those usually don't (in my experience) have to do with object properties and so don't involve delete. They only really come up when you're creating function instances (which is fairly often, if you're setting up event handlers or timer functions, etc.). For instance, consider:

                  function foo() {
                      var listOfThings = /* ...get a list of things... */;
                  
                      // ...do something with `listOfThings`...
                  
                      setInterval(function() {
                         // ...do something that *doesn't* need `listOfThings`...
                      }, 1000);
                  }
                  

                  因為您通過 setInterval 分配給計時器的匿名函數將在函數調用中繼續存在,它會保持對該函數調用期間范圍內所有內容的實時引用(無論它是否使用它)或不).這會將 listOfThings 指向的事物列表保存在內存中.如果計時器功能不需要該列表,那是一個問題.如果您知道該函數不需要它,則可以通過分配 undefinednull 或其他任何內容來釋放 listOfThings 指向的列表listOfThings 完成后:

                  Because your anonymous function you've assigned to a timer via setInterval will survive the function call, it keeps a live reference to everything that was in-scope during that function call (whether it uses it or not). This keeps the list of things that listOfThings points to in memory. If the timer function doesn't need that list, that's a concern. You can release the list that listOfThings points to if you know that the function doesn't need it, by assigning undefined or null or whatever to listOfThings when you're done with it:

                  function foo() {
                  
                      var listOfThings = /* ...get a list of things... */;
                  
                      // ...do something with `listOfThings`...
                  
                      listOfThings = undefined; // Done with it           <== The new bit
                  
                      setInterval(function() {
                         // ...do something that *doesn't* need `listOfThings`...
                      }, 1000);
                  }
                  

                  事件處理函數等也是如此.每當您創建一個函數時,它都會關閉"(保持對它的定義范圍內的任何內容的實時引用).因此,如果您不需要這些東西,您可以通過清除對它們的引用來確保它們不會保留在內存中.(更多:閉包并不復雜)

                  The same is true for event handler functions, etc. Whenever you create a function, it "closes over" (keeps a live reference to) anything in scope where it was defined. So if you don't need those things, you can ensure they're not kept in memory by clearing the references to them. (More: Closures are not complicated)

                  這篇關于Javascript中同一變量上的“new"沒有“delete"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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() 的限制?)

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

                          <small id='8GXZy'></small><noframes id='8GXZy'>

                        1. <tfoot id='8GXZy'></tfoot>
                              <tbody id='8GXZy'></tbody>

                          • <legend id='8GXZy'><style id='8GXZy'><dir id='8GXZy'><q id='8GXZy'></q></dir></style></legend>
                            主站蜘蛛池模板: 久久久人成影片免费观看 | 看a网站 | 欧美日韩精品一区二区天天拍 | 精品国产99 | 少妇精品亚洲一区二区成人 | 中文字幕亚洲精品在线观看 | 午夜视频大全 | 亚洲精品国产电影 | 97av视频| 亚洲色图综合 | 久久国产精品-国产精品 | 精精久久 | 在线观看a视频 | www成人免费视频 | 亚洲一一在线 | 亚洲福利免费 | 日韩av一区二区在线观看 | 91免费在线 | 国产一级毛片视频 | 二区在线视频 | 中文字幕av第一页 | 亚洲午夜视频在线观看 | 91伊人| 久久久久久久久久一区二区 | 欧美日韩亚洲三区 | 国产高清一区二区三区 | 99国内精品久久久久久久 | 久久www免费人成看片高清 | 中文字幕在线观看视频一区 | 九九伦理电影 | 国产高清一区二区三区 | 欧美一级视频免费看 | 亚洲一区二区精品视频 | 亚洲高清视频一区二区 | 大陆一级毛片免费视频观看 | 欧美福利专区 | 亚洲欧美日韩在线不卡 | 欧美精品片 | 精品久久精品 | 亚洲成人观看 | 精品国产一区二区三区免费 |