Note: Please go through my question completely before marking it duplicate or irrelevant, Please ! and also, Please forgive me if it is a silly question ...!
I created two classes one with slots and one without it, as follows:
import guppy
class A(object):
def __init__(self):
self.a = 1
self.b = 2
self.c = 3
class B(object):
__slots__ = ['a', 'b', 'c']
def __init__(self):
self.a = 1
self.b = 2
self.c = 3
a = [A() for i in xrange(1000000)]
b = [B() for i in xrange(1000000)]
print guppy.hpy().heap()
At the end of the program, I am printing the memory cunsumtion of Python heap. To my surprise a program with slots is taking more memory. Here is the output of guppy.hpy().heap():
P.S: I even tried with slots = ('a', 'b', 'c'), result is still the same