Object cleanup

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 30 12:40:11 EDT 2012


On Wed, 30 May 2012 09:01:20 -0700, psaffrey at googlemail.com wrote:

> However, I've found that using guppy, after the methods have returned
> most of the memory is being taken up with BeautifulSoup objects of one
> type or another. I'm not declaring BeautifulSoup objects anywhere else.

What's guppy?


> I've tried assigning None into the "soup" objects at the end of the
> method calls and calling garbage collection manually, but this doesn't
> seem to help. I'd like to find out exactly what object "owns" the
> various BeautifulSoup structures, but I'm quite a new guppy user and I
> can't figure out how to do this.
> 
> How do I force the memory for these soup objects to be freed? Is there
> antyhing else I should be looking at to find out the cause of these
> problems?

If objects aren't being garbage collected, you probably have cycles of 
objects with __del__ methods. Python's reference garbage collector can't 
delete objects in cycles, and the alternative garbage collector can't 
delete objects with __del__ methods.

Try removing the __del__ methods, and see if that fixes the problem.

Also, see the gc module.

http://docs.python.org/library/gc.html



-- 
Steven



More information about the Python-list mailing list