Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The python pickle protocol is written to store arbitrarily complicated data structures. It writes a little computer program to reconstruct a data structure, together with the ones it depends on. It's not particularly constructed to be ''efficient'' in the process, because of the generality it needs to work at.

If you have data structures that barely fit in memory you should probably look into more special-purpose data storage methods (scipy/numpy probably have something decent for matrices)

I checked your example and it doesn't seem there is anything particular leaking. So after the pickling/unpickling is done, the memory is available again. Whether python gives pages back to the operating system depends on implementation details there. I would expect that CPython wouldn't be in too much of a hurry to give 80 Mb back. See for instance