I was looking at the sizes of pickled objects and noticed that non-empty lists change size after unpickling. They grow larger by 24 bytes. The size of empty lists stays the same. If I use the getsizeof
method here, then it shows that the same happens with nested lists, and the size grows by 24 bytes for each non-empty list.
How does this increase happen?
A small example:
import pickle
import sys
li = [1]
with open('test.p', 'wb') as f:
pickle.dump(li, f)
print (getsize(li), sys.getsizeof(li))
with open('test.p', 'rb') as f:
li2 = pickle.load(f)
print (sys.getsizeof(li2))