-1

我的瀏覽器是SRWare Iron 24.0 Portable和Tampermonkey版本是2.12.3124.256或
3.0.3389.11。我寫了下面的userscript:這個腳本爲什麼導致內存泄漏?

// ==UserScript== 
// @name  Night Mode 
// @namespace http://use.i.E.your.homepage/ 
// @version  1.0 
// @description Add night mode style 
// @include  http* 
// @run-at  document-start 
// ==/UserScript== 

function addNightStyle(){ 
    var rules = ['html, body { background: #383838 !important; }', 
     'div { background-color: #383838 !important; }', 
     'header,nav,table,th,tr,td,dl,ul,li,ol,fieldset,form,h1,h2,h3,h4,h5,h6,pre { background: transparent !important;}', 
     '* { color: #B6AA7B !important; }', 
     'a:link,a:link *,a:link:hover,a:link:hover *,a:link:active,a:link:active * { color: #B6AA7B !important; }', 
     'a:visited,a:visited *,a:visited:hover,a:visited:hover *,a:visited:active,a:visited:active * { color: #D9C077 !important; }' 
     ]; 
    with(document.head.appendChild(document.createElement('style'))){ 
     id = 'nightmode'; 
     for(var i=0; i<rules.length; i++){ 
      sheet.insertRule(rules[i], i); 
     } 
    } 
} 
setTimeout(addNightStyle,90); 

當這個腳本是活動的,內存使用和渲染過程中增加虛擬大小逐漸我經歷更多的頁面瀏覽。內存只能通過關閉相應渲染器進程的所有選項卡來釋放。

爲什麼此腳本導致內存泄漏?

如何解決?

+0

我應該'sheet'是什麼? –

+0