Python 3.4+tracemallocfunction
tracemalloc.stop()
tracing control
Stops tracing memory allocations and erases every trace collected so far.
Syntax
tracemalloc.stop()
The data goes away together with tracing: after stop() get_traced_memory() returns (0, 0) and get_object_traceback() returns None for every object. If you need the result, call take_snapshot() BEFORE stop(): a snapshot is a standalone object and survives the shutdown. Calling stop() twice is not an error.
Examples
import tracemalloc
tracemalloc.start()
data = [bytes(100) for _ in range(100)]
snap = tracemalloc.take_snapshot()
tracemalloc.stop()
print(tracemalloc.get_traced_memory()) # → (0, 0)
print(len(snap.traces) > 0) # → True — снимок пережил stop()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy