Python gc Module
Example
Check that garbage collector helpers are available:
import gc
print(hasattr(gc, "collect"))
print(callable(gc.collect))
Try it Yourself »
Definition and Usage
The gc module provides access to the garbage collector and debugging hooks.
Use it to tune collection thresholds, track objects, and manually trigger collection when needed.
Members
Member | Description |
---|---|
collect() | Run a full collection and return the number of unreachable objects found. |
get_count() | Return the current collection counts. |
get_threshold() | Return the collection thresholds. |
set_threshold() | Set the collection thresholds. |
isenabled() | Return whether the automatic collector is enabled. |
enable() | Enable automatic garbage collection. |
disable() | Disable automatic garbage collection. |