Profiling and Memory Modules
gc
Provides controls and inspection for the cyclic garbage collector. CPython reference counting handles many object lifetimes separately; disabling automatic cyclic collection does not disable reference counting. gc.collect requests collection, but exact collection counts depend on runtime state.
Formal Syntax & Structure
python syntaxpython
import gcReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import gcimport weakrefclass Node: passnode = Node()node.link = noderef = weakref.ref(node)del nodegc.collect()print(ref() is None)