Looping-related Memory Leak

Carl Banks pavlovevidence at gmail.com
Thu Jun 26 05:38:17 EDT 2008


On Jun 26, 5:19 am, Tom Davis <binju... at gmail.com> wrote:
> I am having a problem where a long-running function will cause a
> memory leak / balloon for reasons I cannot figure out.  Essentially, I
> loop through a directory of pickled files, load them, and run some
> other functions on them.  In every case, each function uses only local
> variables and I even made sure to use `del` on each variable at the
> end of the loop.  However, as the loop progresses the amount of memory
> used steadily increases.

Do you happen to be using a single Unpickler instance?  If so, change
it to use a different instance each time.  (If you just use the module-
level load function you are already using a different instance each
time.)

Unpicklers hold a reference to everything they've seen, which prevents
objects it unpickles from being garbage collected until it is
collected itself.


Carl Banks



More information about the Python-list mailing list