Python Glossary Русский

Python 3.4+tracemallocfunction

tracemalloc.get_tracemalloc_memory()

memory measurements

Returns how many bytes of memory tracemalloc itself uses to store its traces.

Syntax

tracemalloc.get_tracemalloc_memory() -> int

This is the cost of measuring, not the result: get_traced_memory() does not include it. With a large nframe and millions of small objects the overhead can rival what is being measured, and a traced process may run out of memory where it worked without tracing. The number depends on version and machine — compare it with get_traced_memory(), not with a constant.

Examples

import tracemalloc
tracemalloc.start(25)
data = [str(i) for i in range(10_000)]
overhead = tracemalloc.get_tracemalloc_memory()
print(overhead)  # → ? зависит от версии и машины
print(overhead > 0)  # → True
tracemalloc.stop()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy