Python Glossary Русский

all Python 3gcfunction

gc.get_count()

thresholds and statistics

Returns the collector's current per-generation counters — a tuple of three numbers. The values are machine-dependent.

Syntax

gc.get_count()

The first number is not 'objects in generation 0' but allocations minus deallocations of containers since the last collection; when it exceeds the get_threshold value, a collection starts. The other two count collections of the younger generation. The values change with every line of code and between versions, so leak hunting uses get_stats or tracemalloc, not get_count.

Examples

import gc
print(len(gc.get_count()))  # → 3
print(gc.get_count())  # → ? например (512, 3, 0)
gc.collect()
print(gc.get_count())  # → ? после полной сборки счётчики почти нулевые

See also

Open in the full glossarydocs.python.orgReport an inaccuracy