⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page427.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Stop-and-Copy 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="tex2html6092" HREF="page428.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6090" HREF="page415.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6084" HREF="page426.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6094" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0013400000000000000000">Stop-and-Copy Garbage Collection</A></H1><P><A NAME="secgarbagestopcopy">&#160;</A><P>The section describes a garbage collection approachthat collects garbage <em>and</em> defragments the heapcalled <em>stop-and-copy</em><A NAME=30968>&#160;</A><A NAME=30969>&#160;</A>.When using the stop-and-copy garbage collection algorithm,the heap is divided into two separate regions.At any point in time, all dynamically allocated object instancesreside in only one of the two regions--the <em>active</em> region.The other, <em>inactive</em> region is unoccupied.<P>When the memory in the active region is exhausted,the program is suspended and the garbage-collection algorithm is invoked.The stop-and-copy algorithm copies all of the live objects fromthe active region to the inactive region.As each object is copied, all references contained in that objectare updated to reflect the new locations of the referenced objects.<P>After the copying is completed,the active and inactive regions exchange their roles.Since the stop-and-copy algorithm copies only the live objects,the garbage objects are left behind.In effect, the storage occupied by the garbage is reclaimedall at once when the active region becomes inactive.<P>As the stop-and-copy algorithm copies the live objects fromthe active region to the inactive region,it stores the objects in contiguous memory locations.Thus, the stop-and-copy algorithm automatically defragments the heap.This is the main advantage of the stop-and-copy approachover the mark-and-sweep algorithm described in the preceding section.<P>The costs of the stop-and-copy algorithm are twofold:First, the algorithm requires that <em>all</em> live objectsbe copied every time garbage collection is invoked.If an application program has a large memory footprint,the time required to copy all objects can be quite significant.A second cost associated with stop-and-copy is the factthat it requires twice as much memory as the program actually uses.When garbage collection is finished,at least half of the memory space is unused.<P><BR> <HR><UL> <LI> <A NAME="tex2html6095" HREF="page428.html#SECTION0013410000000000000000">The Copy Algorithm</A></UL><HR><A NAME="tex2html6092" HREF="page428.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6090" HREF="page415.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6084" HREF="page426.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6094" 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 &#169; 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -