Python Glossary Русский

all Python 3gcfunction

gc.enable()

collection control

Turns automatic collection of cyclic garbage back on after gc.disable. It is on by default.

Syntax

gc.enable()

Enabling does not run a collection immediately: it starts when the allocation counter exceeds the threshold, and the accumulated cycles stay in memory until then. If you need it now, call gc.collect. Calls are not counted: two disables are undone by one enable, so nested 'turn it off for a while' blocks in different libraries interfere.

Examples

import gc
gc.disable()
gc.disable()
gc.enable()
print(gc.isenabled())  # → True — одного enable хватило

See also

Open in the full glossarydocs.python.orgReport an inaccuracy