page421.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 42 行
HTML
42 行
<HTML><HEAD><TITLE>Helping the Garbage Collector</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="tex2html6027" HREF="page422.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6025" HREF="page416.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6021" HREF="page420.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6029" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0013120000000000000000">Helping the Garbage Collector</A></H2><P>The preceding section presents strategies for avoiding garbage collection.However, there are times when garbage collection is actually desirable.Imagine a program that requires a significant amount of memory.Suppose the amount of memory required is very close to the amount of memoryavailable for use by the Python virtual machine.The performance of such a program is going to depend on the abilityof the garbage collector to find and reclaimas much unused storage as possible.Otherwise, the garbage collector will run too often.In this case, it pays to help out the garbage collector.<P>How can we help out the garbage collector?Since the garbage collector collects only unreferenced objectsit is necessary to eliminate all referencesto objects that are no longer needed.This can be done by assigning the value <tt>None</tt>to every variable that refers to an object that is no longer needed.Alternatively,the Python <tt>del</tt> statement can be used to removethe binding for a name.Either way,helping the garbage collector requires a program to do a bit more work.<P><HR><A NAME="tex2html6027" HREF="page422.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6025" HREF="page416.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6021" HREF="page420.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6029" 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 + -
显示快捷键?