Back
Close

Journey to Master Python (WIP)

ageekymonk
34.4K views

Slots for scaling

Python stores all the instant attributes of a class in dict. This is useful to add more run time attributes. However if we create thousands of such instances the impact of it on RAM is very high.

If we know that there are no such instance attributes at runtime then we can create millions of such objects without much impact on RAM. This can be achived by using __slots__. __slots__ tells python not to use dict but allocate fixed memory for set of attributes.

Slots
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io