MCPcopy Index your code
hub / github.com/python/cpython / gc_collect

Function gc_collect

Lib/test/support/__init__.py:937–950  ·  view source on GitHub ↗

Force as many objects as possible to be collected. In non-CPython implementations of Python, this is needed because timely deallocation is not guaranteed by the garbage collector. (Even in CPython this can be the case in case of reference cycles.) This means that __del__ methods m

()

Source from the content-addressed store, hash-verified

935
936
937def gc_collect():
938 """Force as many objects as possible to be collected.
939
940 In non-CPython implementations of Python, this is needed because timely
941 deallocation is not guaranteed by the garbage collector. (Even in CPython
942 this can be the case in case of reference cycles.) This means that __del__
943 methods may be called later than expected and weakrefs may remain alive for
944 longer than expected. This function tries its best to force all garbage
945 objects to disappear.
946 """
947 import gc
948 gc.collect()
949 gc.collect()
950 gc.collect()
951
952@contextlib.contextmanager
953def disable_gc():

Callers 15

test_referencesMethod · 0.90
runMethod · 0.90
mainMethod · 0.90
test_asendMethod · 0.90
test_athrowMethod · 0.90
test_acloseMethod · 0.90
test_aclose_throwMethod · 0.90

Calls 1

collectMethod · 0.45

Tested by 15

test_referencesMethod · 0.72
runMethod · 0.72
mainMethod · 0.72
test_asendMethod · 0.72
test_athrowMethod · 0.72
test_acloseMethod · 0.72
test_aclose_throwMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…