CPython immediately frees objects when their reference count hits zero, and uses a generational cyclic garbage collector to detect reference cycles (e.g. parent <-> child graphs). Defining __slots__ replaces the per-instance __dict__ with fixed descriptor slots, cutting memory and speeding attribute access at the cost of disabling arbitrary dynamic attributes.
Follow-up Interview Question · How can an exception traceback or global cache silently keep large objects alive?