Loading...
Loading...
Browse 3 real-world technical and behavioral interview questions about Slots. Review scenarios, edge cases, and architectural best practices.
Into per-object overhead: in CPython on a 64-bit build every object carries a 16-byte header, every field is itself a boxed object reached through an 8-byte pointer, and each instance has a dictionary. Slots remove the dictionary, and a columnar layout removes the objects. Use this memory layout answer to show the decision, trade-off, and evidence rather than a memorised definition.
A Python descriptor implements __get__, and optionally __set__ or __delete__, to control attribute access; @property is a data descriptor that wins over the instance dictionary.
CPython frees an object the instant its reference count reaches zero, so steady growth is usually something still holding a reference rather than a leak. The cycle collector reclaims only reference cycles. Measure with tracemalloc first, then use __slots__ or generators to cut per-object and peak cost.