sys.getsizeof

A Python function that reports how many bytes an object itself occupies in memory.

In more detail

For a list it counts the list object and its array of pointers, but not the objects those pointers refer to. Watching it as a list grows shows Python over-allocating capacity in jumps rather than one slot at a time. It is the quickest way to put a number on a structure's memory cost.

Example

sys.getsizeof([])  # 56 on a typical 64-bit build

Related terms

Taught in

References