Module gc
[hide private]
[frames] | no frames]

Module gc

This module provides access to the garbage collector for reference cycles.

enable() -- Enable automatic garbage collection. disable() -- Disable automatic garbage collection. isenabled() -- Returns true if automatic collection is enabled. collect() -- Do a full collection right now. get_count() -- Return the current collection counts. set_debug() -- Set debugging flags. get_debug() -- Get debugging flags. set_threshold() -- Set the collection thresholds. get_threshold() -- Return the current the collection thresholds. get_objects() -- Return a list of all objects tracked by the collector. get_referrers() -- Return the list of objects that refer to an object. get_referents() -- Return the list of objects that an object refers to.

Functions [hide private]
n
collect(generation=...)
With no arguments, run a full collection.
None
disable()
Disable automatic garbage collection.
None
enable()
Enable automatic garbage collection.
(count0, count1, count2)
get_count()
Return the current collection counts
flags
get_debug()
Get the garbage collection debugging flags.
[...]
get_objects()
Return a list of objects tracked by the collector (excluding the list returned).
list
get_referents(*objs)
Return the list of objects that are directly referred to by objs.
list
get_referrers(*objs)
Return the list of objects that directly refer to any of objs.
(threshold0, threshold1, threshold2)
get_threshold()
Return the current collection thresholds
status
isenabled()
Returns true if automatic garbage collection is enabled.
None
set_debug(flags)
Set the garbage collection debugging flags.
 
set_threshold(...)
set_threshold(threshold0, [threshold1, threshold2]) -> None
Variables [hide private]
  DEBUG_COLLECTABLE = 2
  DEBUG_INSTANCES = 8
  DEBUG_LEAK = 62
  DEBUG_OBJECTS = 16
  DEBUG_SAVEALL = 32
  DEBUG_STATS = 1
  DEBUG_UNCOLLECTABLE = 4
  garbage = []
Function Details [hide private]

collect(generation=...)

 

With no arguments, run a full collection. The optional argument may be an integer specifying which generation to collect. A ValueError is raised if the generation number is invalid.

The number of unreachable objects is returned.

Returns: n

set_debug(flags)

 
Set the garbage collection debugging flags. Debugging information is
written to sys.stderr.

flags is an integer and can have the following bits turned on:

  DEBUG_STATS - Print statistics during collection.
  DEBUG_COLLECTABLE - Print collectable objects found.
  DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects found.
  DEBUG_INSTANCES - Print instance objects.
  DEBUG_OBJECTS - Print objects other than instances.
  DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.
  DEBUG_LEAK - Debug leaking programs (everything but STATS).

Returns: None

set_threshold(...)

 

set_threshold(threshold0, [threshold1, threshold2]) -> None

Sets the collection thresholds. Setting threshold0 to zero disables collection.