python: class vs tuple huge memory overhead (?)
I'm storing a lot of complex data in tuples/lists, but would prefer to use small wrapper classes to make the data structures easier to understand, e.g. class Person: def __init__(self, first, last): self.first = first self.last = last p = Person('foo', 'bar') print(p.last) ... would be preferable over p = ['foo', 'bar'] print(p[1]) ... however there seems to be a horrible memory overhead: l = [Person('foo', 'bar') for i in range(10000000)] # ipython now taks 1.7 GB RAM and del l l = [('foo', 'bar') for i in range(10000000)] # now just 118 MB RAM Why? is there any obvious alternative solution