I was trying to understand use of slots in Python, so I created two classes, one with slots and one without it, then, I created about a million objects and print the size of both the objects:
>>> class Foo(object): pass
>>> class Bar(object): __slots__ = ()
>>> foos = [Foo() for f in xrange(1000000)]
>>> bars = [Bar() for b in xrange(1000000)]
>>> import sys
>>> sys.getsizeof(foos)
4348732
>>> sys.getsizeof(bars)
4348732
Surprisingly both the objects are of same size. So now I am confused why is it said that slots save memory ?
P.S. I tried this on Linux, Python 2.7
This is not duplicate of: Usage of __slots__?
Here I want to know why the memory consumption in both the scenarios is same?