aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/javascript/memory_management/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-tw/web/javascript/memory_management/index.html')
-rw-r--r--files/zh-tw/web/javascript/memory_management/index.html18
1 files changed, 9 insertions, 9 deletions
diff --git a/files/zh-tw/web/javascript/memory_management/index.html b/files/zh-tw/web/javascript/memory_management/index.html
index defd71cce3..d63cb223ff 100644
--- a/files/zh-tw/web/javascript/memory_management/index.html
+++ b/files/zh-tw/web/javascript/memory_management/index.html
@@ -133,7 +133,7 @@ oa = null; // 現在把 oa 變成 null
<h4 id="限制:循環">限制:循環</h4>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>當涉及到循環時有一個限制。在下面的例子中,創造兩個物件並相互參考,從而製作一個循環。當呼叫函式時,他們應該超出作用範圍,因此他們實際上是無用且可釋放。但垃圾回收參考計數演算法會認為,兩個物件都至少被參考一次,因此兩個都是不能被回收的。</span></p>
+<p>當涉及到循環時有一個限制。在下面的例子中,創造兩個物件並相互參考,從而製作一個循環。當呼叫函式時,他們應該超出作用範圍,因此他們實際上是無用且可釋放。但垃圾回收參考計數演算法會認為,兩個物件都至少被參考一次,因此兩個都是不能被回收的。</p>
<pre class="brush: js notranslate">function f() {
var o = {};
@@ -149,7 +149,7 @@ f();
<h4 id="真實案例">真實案例</h4>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>Internet Explorer 6和7有一個DOM物件的垃圾回收參考計數。循環是一個造成記憶體洩漏(memory leaks)的常見問題:</span></p>
+<p>Internet Explorer 6和7有一個DOM物件的垃圾回收參考計數。循環是一個造成記憶體洩漏(memory leaks)的常見問題:</p>
<pre class="brush: js notranslate">var div;
window.onload = function() {
@@ -159,23 +159,23 @@ window.onload = function() {
};
</pre>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>在上面的例子中,DOM 元素「myDivElement」在「circularReference」屬性中有一個循環參考。如果該屬性未被直接刪除或為零,垃圾回收參考計數將視其始終至少有一個參考保持不變,並將 DOM 元素保存在記憶體裡,即使它已從DOM 樹中移除。如果該 DOM 元素擁有大量資料(如同上面的例子中的 lotsOfData 屬性),則此資料所佔用的記憶體將永遠不會釋放。</span></p>
+<p>在上面的例子中,DOM 元素「myDivElement」在「circularReference」屬性中有一個循環參考。如果該屬性未被直接刪除或為零,垃圾回收參考計數將視其始終至少有一個參考保持不變,並將 DOM 元素保存在記憶體裡,即使它已從DOM 樹中移除。如果該 DOM 元素擁有大量資料(如同上面的例子中的 lotsOfData 屬性),則此資料所佔用的記憶體將永遠不會釋放。</p>
<h3 id="標記和清理演算法">標記和清理演算法</h3>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>這個演算法將「這個物件再也不會被使用」的定義縮減到「這個物件不可到達」。</span></p>
+<p>這個演算法將「這個物件再也不會被使用」的定義縮減到「這個物件不可到達」。</p>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>這個演算法假設一組物件,其名為「根 (roots)」(在 JavaScript 中,根(roots)是全局物件)。垃圾回收器定期從這些根開始,尋訪所有被根參考的物件與那些物件參考的物件。垃圾回收器會回收那些沒有被尋訪的到物件。</span></p>
+<p>這個演算法假設一組物件,其名為「根 (roots)」(在 JavaScript 中,根(roots)是全局物件)。垃圾回收器定期從這些根開始,尋訪所有被根參考的物件與那些物件參考的物件。垃圾回收器會回收那些沒有被尋訪的到物件。</p>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>這個演算法比前一個演算法更好,因為一個不被任何物件參考的物件,一定無法從根被尋訪到。然而,一個無法從根被尋訪到的物件,不一定不被任何物件參考,可以在循環的例子中發現這件事。</span></p>
+<p>這個演算法比前一個演算法更好,因為一個不被任何物件參考的物件,一定無法從根被尋訪到。然而,一個無法從根被尋訪到的物件,不一定不被任何物件參考,可以在循環的例子中發現這件事。</p>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>截至2012年,所有現代瀏覽器都使用標記和清理的垃圾回收器。 在過去的幾年裡,JavaScript 垃圾回收領域的所有改進都是對這個演算法的實作與改進,但並未改進垃圾回收演算法本身,也沒有縮減垃圾的定義 「這個物件再也不會被使用」。</span></p>
+<p>截至2012年,所有現代瀏覽器都使用標記和清理的垃圾回收器。 在過去的幾年裡,JavaScript 垃圾回收領域的所有改進都是對這個演算法的實作與改進,但並未改進垃圾回收演算法本身,也沒有縮減垃圾的定義 「這個物件再也不會被使用」。</p>
<h4 id="循環不再是一個問題">循環不再是一個問題</h4>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>在上面的第一個範例中,函式呼叫返回後,那兩個物件不再被全局物件可以尋訪到的物件參考。 因此,它們將被垃圾回收器發現,視為不可達到的。</span></p>
+<p>在上面的第一個範例中,函式呼叫返回後,那兩個物件不再被全局物件可以尋訪到的物件參考。 因此,它們將被垃圾回收器發現,視為不可達到的。</p>
-<p><span style='background-color: #ffffff; color: #333333; display: inline !important; float: none; font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif; font-size: 16px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap;'>第二個範例也是一樣的。 一旦 div 和它的處理程序從根本上無法尋訪,它們都會被垃圾回收掉,儘管他們自身相互參考。</span></p>
+<p>第二個範例也是一樣的。 一旦 div 和它的處理程序從根本上無法尋訪,它們都會被垃圾回收掉,儘管他們自身相互參考。</p>
<h4 id="限制:物件必須明顯的不可達到">限制:物件必須明顯的不可達到</h4>