pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

      <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="s3e8n8j" 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="lfvnhvm" 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="napq8y3" 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>

                          • 主站蜘蛛池模板: 安徽千住锡膏_安徽阿尔法锡膏锡条_安徽唯特偶锡膏_卡夫特胶水-芜湖荣亮电子科技有限公司 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 石磨面粉机|石磨面粉机械|石磨面粉机组|石磨面粉成套设备-河南成立粮油机械有限公司 | 成都顶呱呱信息技术有限公司-贷款_个人贷款_银行贷款在线申请 - 成都贷款公司 | 许昌奥仕达自动化设备有限公司 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 企业VI设计_LOGO设计公司_品牌商标设计_【北京美研】 | 通用磨耗试验机-QUV耐候试验机|久宏实业百科 | 卫生型双针压力表-高温防腐差压表-安徽康泰电气有限公司 | 继电器模组-IO端子台-plc连接线-省配线模组厂家-世麦德 | 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 防腐木批发价格_深圳_惠州_东莞防腐木厂家_森源(深圳)防腐木有限公司 | 家乐事净水器官网-净水器厂家「官方」 | 优考试_免费在线考试系统_培训考试系统_题库系统_组卷答题系统_匡优考试 | PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 下水道疏通_管道疏通_马桶疏通_附近疏通电话- 立刻通 | 上海噪音治理公司-专业隔音降噪公司-中广通环保 | 水平筛厂家-三轴椭圆水平振动筛-泥沙震动筛设备_山东奥凯诺矿机 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 预制直埋蒸汽保温管-直埋管道-聚氨酯发泡保温管厂家 - 唐山市吉祥保温工贸有限公司 | 健康管理师报考条件,考试时间,报名入口—首页 | 罐体电伴热工程-消防管道电伴热带厂家-山东沃安电气 | 热回收盐水机组-反应釜冷水机组-高低温冷水机组-北京蓝海神骏科技有限公司 | 分光色差仪,测色仪,反透射灯箱,爱色丽分光光度仪,美能达色差仪维修_苏州欣美和仪器有限公司 | 生态板-实木生态板-生态板厂家-源木原作生态板品牌-深圳市方舟木业有限公司 | 吉祥新世纪铝塑板_生产铝塑板厂家_铝塑板生产厂家_临沂市兴达铝塑装饰材料有限公司 | 刺绳_刀片刺网_刺丝滚笼_不锈钢刺绳生产厂家_安平县浩荣金属丝网制品有限公司-安平县浩荣金属丝网制品有限公司 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | 飞歌臭氧发生器厂家_水处理臭氧发生器_十大臭氧消毒机品牌 | 【官网】博莱特空压机,永磁变频空压机,螺杆空压机-欧能优 | 偏心半球阀-电动偏心半球阀-调流调压阀-旋球阀-上欧阀门有限公司 | 立式矫直机_卧式矫直机-无锡金矫机械制造有限公司 | 微型气象仪_气象传感器_防爆气象传感器-天合传感器大全 | 顶空进样器-吹扫捕集仪-热脱附仪-二次热解吸仪-北京华盛谱信仪器 | 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 合肥废气治理设备_安徽除尘设备_工业废气处理设备厂家-盈凯环保 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 北京开业庆典策划-年会活动策划公司-舞龙舞狮团大鼓表演-北京盛乾龙狮鼓乐礼仪庆典策划公司 |