Python 3.4+tracemallocfunction
tracemalloc.clear_traces()
tracing control
Erases the collected allocation traces without switching tracing off.
Syntax
tracemalloc.clear_traces()
Unlike a stop()/start() pair, the frame limit is kept and tracing keeps running. But objects allocated before the clear are now invisible: freeing them does not lower the counter, and get_object_traceback() returns None for them. The peak is reset too; to reset only the peak there is reset_peak().
Examples
import tracemalloc
tracemalloc.start()
old = bytes(10_000)
tracemalloc.clear_traces()
print(tracemalloc.is_tracing(), tracemalloc.get_traced_memory()) # → True (0, 0)
print(tracemalloc.get_object_traceback(old)) # → None
tracemalloc.stop()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy