page429.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 45 行
HTML
45 行
<HTML><HEAD><TITLE>Mark-and-Compact Garbage Collection</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html6113" HREF="page430.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6111" HREF="page415.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6105" HREF="page428.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6115" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0013500000000000000000">Mark-and-Compact Garbage Collection</A></H1><P>The mark-and-sweep algorithm described in Section <A HREF="page425.html#secgarbagemarksweep"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>has the unfortunate tendency to fragment the heap.The stop-and-copy algorithm described in Section <A HREF="page427.html#secgarbagestopcopy"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>avoids fragmentation at the expense of doubling the size of the heap.This section describesthe <em>mark-and-compact</em><A NAME=31413> </A><A NAME=31414> </A>approach to garbage collection which eliminates fragmentation without the space penalty of stop-and-copy.<P>The mark-and-compact algorithm consists of two phases:In the first phase, it finds and marks all live objects.The first phase is called the <em>mark</em> phase.In the second phase, the garbage collection algorithmcompacts the heap by moving all the live objectsinto contiguous memory locations.The second phase is called the <em>compaction</em><A NAME=31417> </A> phase.The algorithm can be expressed as follows:<PRE>def markAndCompact(): for r in roots: mark(r) compact()</PRE><P><BR> <HR><UL> <LI> <A NAME="tex2html6116" HREF="page430.html#SECTION0013510000000000000000">Handles</A></UL><HR><A NAME="tex2html6113" HREF="page430.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6111" HREF="page415.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6105" HREF="page428.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6115" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?