@@ -288,6 +288,75 @@ \section{String Methods}
288288words, \code {s.join(seq)} is equivalent to the old
289289\code {string.join(seq, s)}.
290290
291+ % ======================================================================
292+ \section {Optional Collection of Cycles }
293+
294+ The C implementation of Python uses reference counting to implement
295+ garbage collection. Every Python object maintains a count of the
296+ number of references pointing to itself, and adjusts the count as
297+ references are created or destroyed. Once the reference count reaches
298+ zero, the object is no longer accessible, since you need to have a
299+ reference to an object to access it, and if the count is zero, no
300+ references exist any longer.
301+
302+ Reference counting has some pleasant properties: it's easy to
303+ understand and implement, and the resulting implementation is
304+ portable, fairly fast, and reacts well with other libraries that
305+ implement their own memory handling schemes. The major problem with
306+ reference counting is that it sometimes doesn't realise that objects
307+ are no longer accessible, resulting in a memory leak. This happens
308+ when there are cycles of references.
309+
310+ Consider the simplest possible cycle,
311+ a class instance which has a reference to itself:
312+
313+ \begin {verbatim }
314+ instance = SomeClass()
315+ instance.myself = instance
316+ \end {verbatim }
317+
318+ After the above two lines of code have been executed, the reference
319+ count of \code {instance} is 2; one reference is from the variable
320+ named \samp {'instance'}, and the other is from the \samp {myself}
321+ attribute of the instance.
322+
323+ If the next line of code is \code {del instance}, what happens? The
324+ reference count of \code {instance} is decreased by 1, so it has a
325+ reference count of 1; the reference in the \samp {myself} attribute
326+ still exists. Yet the instance is no longer accessible through Python
327+ code, and it could be deleted. Several objects can participate in a
328+ cycle if they have references to each other, causing all of the
329+ objects to be leaked.
330+
331+ An experimental step has been made toward fixing this problem. When
332+ compiling Python, the \verb |--with-cycle-gc | option can be specified.
333+ This causes a cycle detection algorithm to be periodically executed,
334+ which looks for inaccessible cycles and deletes the objects involved.
335+ A new \module {gc} module provides functions to perform a garbage
336+ collection, obtain debugging statistics, and tuning the collector's parameters.
337+
338+ Why isn't cycle detection enabled by default? Running the cycle detection
339+ algorithm takes some time, and some tuning will be required to
340+ minimize the overhead cost. It's not yet obvious how much performance
341+ is lost, because benchmarking this is tricky and depends crucially
342+ on how often the program creates and destroys objects.
343+
344+ Several people tackled this problem and contributed to a solution. An
345+ early implementation of the cycle detection approach was written by
346+ Toby Kelsey. The current algorithm was suggested by Eric Tiedemann
347+ during a visit to CNRI, and Guido van Rossum and Neil Schemenauer
348+ wrote two different implementations, which were later integrated by
349+ Neil. Lots of other people offered suggestions along the way; the
350+ March 2000 archives of the python-dev mailing list contain most of the
351+ relevant discussion, especially in the threads titled `` Reference
352+ cycle collection for Python'' and `` Finalization again'' .
353+
354+
355+ % ======================================================================
356+ \section {New XML Code }
357+
358+ XXX write this section...
359+
291360% ======================================================================
292361\section {Porting to 2.0 }
293362
@@ -377,70 +446,6 @@ \section{Porting to 2.0}
377446% of a problem since no one should have been doing that in the first
378447% place.
379448
380- % ======================================================================
381- \section {Optional Collection of Cycles }
382-
383- The C implementation of Python uses reference counting to implement
384- garbage collection. Every Python object maintains a count of the
385- number of references pointing to itself, and adjusts the count as
386- references are created or destroyed. Once the reference count reaches
387- zero, the object is no longer accessible, since you need to have a
388- reference to an object to access it, and if the count is zero, no
389- references exist any longer.
390-
391- Reference counting has some pleasant properties: it's easy to
392- understand and implement, and the resulting implementation is
393- portable, fairly fast, and reacts well with other libraries that
394- implement their own memory handling schemes. The major problem with
395- reference counting is that it sometimes doesn't realise that objects
396- are no longer accessible, resulting in a memory leak. This happens
397- when there are cycles of references.
398-
399- Consider the simplest possible cycle,
400- a class instance which has a reference to itself:
401-
402- \begin {verbatim }
403- instance = SomeClass()
404- instance.myself = instance
405- \end {verbatim }
406-
407- After the above two lines of code have been executed, the reference
408- count of \code {instance} is 2; one reference is from the variable
409- named \samp {'instance'}, and the other is from the \samp {myself}
410- attribute of the instance.
411-
412- If the next line of code is \code {del instance}, what happens? The
413- reference count of \code {instance} is decreased by 1, so it has a
414- reference count of 1; the reference in the \samp {myself} attribute
415- still exists. Yet the instance is no longer accessible through Python
416- code, and it could be deleted. Several objects can participate in a
417- cycle if they have references to each other, causing all of the
418- objects to be leaked.
419-
420- An experimental step has been made toward fixing this problem. When
421- compiling Python, the \verb |--with-cycle-gc | option can be specified.
422- This causes a cycle detection algorithm to be periodically executed,
423- which looks for inaccessible cycles and deletes the objects involved.
424- A new \module {gc} module provides functions to perform a garbage
425- collection, obtain debugging statistics, and tuning the collector's parameters.
426-
427- Why isn't cycle detection enabled by default? Running the cycle detection
428- algorithm takes some time, and some tuning will be required to
429- minimize the overhead cost. It's not yet obvious how much performance
430- is lost, because benchmarking this is tricky and depends crucially
431- on how often the program creates and destroys objects.
432-
433- Several people tackled this problem and contributed to a solution. An
434- early implementation of the cycle detection approach was written by
435- Toby Kelsey. The current algorithm was suggested by Eric Tiedemann
436- during a visit to CNRI, and Guido van Rossum and Neil Schemenauer
437- wrote two different implementations, which were later integrated by
438- Neil. Lots of other people offered suggestions along the way; the
439- March 2000 archives of the python-dev mailing list contain most of the
440- relevant discussion, especially in the threads titled `` Reference
441- cycle collection for Python'' and `` Finalization again'' .
442-
443-
444449% ======================================================================
445450\section {Core Changes }
446451
@@ -672,8 +677,8 @@ \section{New modules}
672677\module {dircmp} modules, which have now become deprecated.
673678(Contributed by Gordon MacMillan and Moshe Zadka.)
674679
675- \item {\module {linuxaudio }:} Support for the \file {/dev/audio} device on Linux,
676- a twin to the existing \module {sunaudiodev} module.
680+ \item {\module {linuxaudiodev }:} Support for the \file {/dev/audio}
681+ device on Linux, a twin to the existing \module {sunaudiodev} module.
677682(Contributed by Peter Bosch.)
678683
679684\item {\module {mmap}:} An interface to memory-mapped files on both
@@ -684,7 +689,7 @@ \section{New modules}
684689module. (Contributed by Sam Rushing, with some extensions by
685690A.M. Kuchling.)
686691
687- \item {\module {PyExpat }:} An interface to the Expat XML parser.
692+ \item {\module {pyexpat }:} An interface to the Expat XML parser.
688693(Contributed by Paul Prescod.)
689694
690695\item {\module {robotparser}:} Parse a \file {robots.txt} file, which is
0 commit comments