1.Object overhead and references, for memory investigation
Every 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.
Key features
- sys.getsizeof(obj) reports real bytes, including overhead — good for spotting one large object
- An object is freed only once nothing references it — a lingering reference is a common growth cause
- a = b never copies — both names reference the same object, so mutating either affects both
- gc.get_referrers(obj) answers "what is still holding this object" during an investigation
- A steadily growing sys.getsizeof() on one container signals an unbounded cache or leak
Command
import sys
sys.getsizeof(obj) # real size, including overhead
import gc
gc.get_referrers(obj) # what is still referencing obj -- for investigating a leakEvery object has real overhead; an object survives as long as anything references it — ask what still references it.