Python 3.4+sysfunction
sys.getallocatedblocks()
memory
Returns the number of memory blocks the interpreter has allocated right now, regardless of size. A utility for hunting leaks.
Syntax
sys.getallocatedblocks()
The value shifts from call to call because of internal caches, so watch the trend over a loop rather than one number, and call gc.collect() first. It does not count bytes — use tracemalloc for that. An implementation that cannot compute it may return 0.
Examples
import gc, sys
gc.collect()
before = sys.getallocatedblocks()
data = [[i] for i in range(10_000)]
print(sys.getallocatedblocks() - before > 5_000) # → True
print(before) # → ? 30000 — зависит от версии и сборки
See also
Open in the full glossarydocs.python.orgReport an inaccuracy