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

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

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

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

      1. 如何強制 JavaScript 深度復制字符串?

        How to force JavaScript to deep copy a string?(如何強制 JavaScript 深度復制字符串?)
        • <bdo id='evowi'></bdo><ul id='evowi'></ul>
        • <small id='evowi'></small><noframes id='evowi'>

          <legend id='evowi'><style id='evowi'><dir id='evowi'><q id='evowi'></q></dir></style></legend>
          <tfoot id='evowi'></tfoot>

                <tbody id='evowi'></tbody>

            • <i id='evowi'><tr id='evowi'><dt id='evowi'><q id='evowi'><span id='evowi'><b id='evowi'><form id='evowi'><ins id='evowi'></ins><ul id='evowi'></ul><sub id='evowi'></sub></form><legend id='evowi'></legend><bdo id='evowi'><pre id='evowi'><center id='evowi'></center></pre></bdo></b><th id='evowi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='evowi'><tfoot id='evowi'></tfoot><dl id='evowi'><fieldset id='evowi'></fieldset></dl></div>
                  本文介紹了如何強制 JavaScript 深度復制字符串?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一些看起來像這樣的 javascript 代碼:

                  var myClass = {編號:{}myFunc:函數(巨大字符串){var id = huge_string.substr(0,2);ids[id] = 真;}}

                  稍后,該函數被一些大字符串 (100 MB+) 調用.我只想保存在每個字符串中找到的短 id.但是,谷歌瀏覽器的子字符串函數(實際上是我的代碼中的正則表達式)只返回一個切片字符串"對象,它引用了原始對象.因此,在對 myFunc 的一系列調用之后,我的 chrome 選項卡內存不足,因為臨時 huge_string 對象無法被垃圾回收.

                  如何復制字符串 id 以便不維護對 huge_string 的引用,并且 huge_string 可以垃圾收集了嗎?

                  解決方案

                  JavaScript 的 ECMAScript 實現因瀏覽器而異,但對于 Chrome,許多字符串操作(substr、slice、regex 等)只是保留對原始字符串,而不是復制字符串.這是 Chrome 中的一個已知問題(

                  I have some javascript code which looks like this:

                  var myClass = {
                    ids: {}
                    myFunc: function(huge_string) {
                       var id = huge_string.substr(0,2);
                       ids[id] = true;
                    }
                  }
                  

                  Later the function gets called with some large strings (100 MB+). I only want to save a short id which I find in each string. However, the Google Chrome's substring function (actually regex in my code) only returns a "sliced string" object, which references the original. So after a series of calls to myFunc, my chrome tab runs out of memory because the temporary huge_string objects are not able to be garbage collected.

                  How can I make a copy of the string id so that a reference to the huge_string is not maintained, and the huge_string can be garbage collected?

                  解決方案

                  JavaScript's implementation of ECMAScript can vary from browser to browser, however for Chrome, many string operations (substr, slice, regex, etc.) simply retain references to the original string rather than making copies of the string. This is a known issue in Chrome (Bug #2869). To force a copy of the string, the following code works:

                  var string_copy = (' ' + original_string).slice(1);
                  

                  This code works by appending a space to the front of the string. This concatenation results in a string copy in Chrome's implementation. Then the substring after the space can be referenced.

                  This problem with the solution has been recreated here: http://jsfiddle.net/ouvv4kbs/1/

                  WARNING: takes a long time to load, open Chrome debug console to see a progress printout.

                  // We would expect this program to use ~1 MB of memory, however taking
                  // a Heap Snapshot will show that this program uses ~100 MB of memory.
                  // If the processed data size is increased to ~1 GB, the Chrome tab
                  // will crash due to running out of memory.
                  
                  function randomString(length) {
                    var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
                    var result = '';
                    for (var i = 0; i < length; i++) {
                      result +=
                          alphabet[Math.round(Math.random() * (alphabet.length - 1))];
                    }
                    return result;
                  };
                  
                  var substrings = [];
                  var extractSubstring = function(huge_string) {
                    var substring = huge_string.substr(0, 100 * 1000 /* 100 KB */);
                    // Uncommenting this line will force a copy of the string and allow
                    // the unused memory to be garbage collected
                    // substring = (' ' + substring).slice(1);
                    substrings.push(substring);
                  };
                  
                  // Process 100 MB of data, but only keep 1 MB.
                  for (var i =  0; i < 10; i++) {
                    console.log(10 * (i + 1) + 'MB processed');
                    var huge_string = randomString(10 * 1000 * 1000 /* 10 MB */);
                    extractSubstring(huge_string);
                  }
                  
                  // Do something which will keep a reference to substrings around and
                  // prevent it from being garbage collected.
                  setInterval(function() {
                    var i = Math.round(Math.random() * (substrings.length - 1));
                    document.body.innerHTML = substrings[i].substr(0, 10);
                  }, 2000);
                  

                  這篇關于如何強制 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() 的限制?)

                      1. <legend id='WpHjl'><style id='WpHjl'><dir id='WpHjl'><q id='WpHjl'></q></dir></style></legend>

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

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

                        <tfoot id='WpHjl'></tfoot>
                          <tbody id='WpHjl'></tbody>
                            <bdo id='WpHjl'></bdo><ul id='WpHjl'></ul>

                          • 主站蜘蛛池模板: 国产999精品久久久影片官网 | 日韩欧美综合 | 国产精品区二区三区日本 | 久久精品色欧美aⅴ一区二区 | 精品一区二区久久久久久久网站 | 日本二区| 日韩精品一区二区三区四区视频 | 国产精品日韩欧美一区二区三区 | 国产精品视频在线播放 | 久久综合成人精品亚洲另类欧美 | 久久国产精品一区二区三区 | 精品欧美久久 | 99精品免费视频 | 久久国产精品久久久久 | 毛片在线看看 | 91婷婷韩国欧美一区二区 | 国产目拍亚洲精品99久久精品 | 国产欧美精品一区 | 久久精品视频亚洲 | 国产精品黄色 | 视频一区二区在线观看 | 亚洲精品国产电影 | 天天弄天天操 | 久在线视频播放免费视频 | 亚洲激情在线观看 | 国产精品99久久久久久久久久久久 | 久久国产精品一区二区三区 | 欧美日韩亚洲国产综合 | 免费骚视频 | 欧美精品乱码99久久影院 | 天天欧美| 国产精品日韩欧美一区二区三区 | 一级午夜aaa免费看三区 | 成人av电影天堂 | 久久久国产一区二区三区 | 三级特黄特色视频 | 综合网视频 | 色一阁| 亚洲国产成人在线视频 | 久久久一区二区三区 | 一区二区三区在线免费观看 |