Object overhead and references, for memory investigation
standardintermediateEvery object costs real bytes beyond its logical content, and a variable is a reference, not a copy — investigating why memory keeps growing means knowing what still references each object, not just counting objects.
Think of it as
When memory keeps climbing, the question is never "how big is one object" — it is "why is this object still referenced, when I expected it to be freed by now." Overhead explains the baseline cost; references explain why something outlives its expected lifetime.
What we're doing: Trace a container's real memory size as it grows, the concrete first step in investigating a suspected leak.
- 3
- A dict standing in for an unbounded cache — nothing ever removes entries from it.
- 6
- Sampling sys.getsizeof() at intervals is the same technique used to spot a real leak in a long-running process.
[224, 224, 224, 224, 224]Why this works: sys.getsizeof() on a dict only reports the size of the hash table itself, not the objects it references — this is exactly the trap that makes investigating real memory growth harder than one size check: the dict's own reported size barely moves even as it holds increasingly many large lists, which is why a real investigation needs tracemalloc's full accounting (see memory-profiling-in-practice), not sys.getsizeof() alone.
Remember: Every object has real overhead; an object survives as long as anything references it — ask what still references it.
See also: memory allocation and object overhead · names vs objects and references · memory leaks in practice

