On this page
gc.collect
Up: gc | Next: gc.disable
Rel: gc.disable, gc.enable, gc.freeze, gc.get_count
Ref: docs.python.org — gc.collect
Tags: #public #python3 #stdlib #gc
Import
import gc
from gc import collect
Signature & Overview
gc.collect(generation=2)
Run the garbage collector.
Usage
import gc
collected = gc.collect()
assert isinstance(collected, int) and collected >= 0
Gotchas
- Only collects cyclic garbage: Non-cyclic objects are freed immediately by reference counting when their refcount hits 0.
REPL Inspect
from gc import collect
help(collect)
Linked from
- tuts/python3/stdlib_module/gc
- tuts/python3/stdlib_module/gc/disable
- tuts/python3/stdlib_module/gc/enable
- tuts/python3/stdlib_module/gc/freeze
- tuts/python3/stdlib_module/gc/get_count
- tuts/python3/stdlib_module/gc/get_debug
- tuts/python3/stdlib_module/gc/get_freeze_count
- tuts/python3/stdlib_module/gc/get_objects
- tuts/python3/stdlib_module/gc/get_referents
- tuts/python3/stdlib_module/gc/get_referrers
- tuts/python3/stdlib_module/gc/get_stats
- tuts/python3/stdlib_module/gc/get_threshold
- tuts/python3/stdlib_module/gc/is_finalized
- tuts/python3/stdlib_module/gc/is_tracked
- tuts/python3/stdlib_module/gc/isenabled
- tuts/python3/stdlib_module/gc/set_debug
- tuts/python3/stdlib_module/gc/set_threshold
- tuts/python3/stdlib_module/gc/unfreeze
Related notes
- tuts/python3/stdlib_module/gc/disable Linked here; links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/enable Linked here; links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/freeze Linked here; links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/get_count Linked here; links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/gc/get_debug links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/get_freeze_count links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/get_objects links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/get_referents links to this page; shared tags: #gc, #stdlib
- tuts/python3/stdlib_module/gc/get_referrers links to this page; shared tags: #gc, #stdlib