Reference Counting and Garbage Collection

Reference counts are increased by...

  • Variable assignment
  • Inclusion of an object in a container (list, tuple, dictionary, etc...).

Reference counts are decreased when...

  • Local reference goes out of scope (variable name is destroyed).
  • Variable name is bound to another object.
  • Object is removed from a container.
  • The variable name is explicitly destroyed using 'del' statement
     del a

Objects destroyed when reference count reaches zero

  • Well, unless there are circular references.
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 47
July 17, 2000, beazley@cs.uchicago.edu
>>>