Python Profiling and Troubleshooting Cheat Sheet/Force a garbage collection cycle

Useful for experiments while diagnosing leaks.

Section: Memory Growth

Force a garbage collection cycle

python
python
import gc

unreachable = gc.collect()
print(unreachable)

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Memory Growth
Show garbage collector stats
Inspect GC activity when memory grows unexpectedly.
OpenIn sheetpythonsame section
Show import statements as they happen
Print detailed import resolution activity.
Save cProfile output to a file
Store profile stats for later analysis.
Print site-package configuration
Inspect interpreter paths and site initialization.
Inspect saved profile stats
Read and sort a saved profile run.