You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to beauti...@googlegroups.com
I have a screen-scrapping application using BeautifulSoup. I have an object with two methods, each of which declares a BeautifulSoup object to do some parsing like this:
soup = BeautifulSoup(file(summarypath))
I presumed that after the method returns it the soup objects would be freed, but it seems that they are not. I've been using guppy/heapy:
to inspect the heap, and BeautifulSoup data structures are still consuming memory after those methods have returned. Is there something else I need to do to get this memory released?
There is a more detailed post about this problem here:
but I thought this might be soup specific and worth asking here.
Peter
Leonard Richardson
unread,
May 31, 2012, 8:23:10 AM5/31/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to beauti...@googlegroups.com
Peter,
Every object in a Beautiful Soup parse tree is connected to other
objects through navigational members like .parent and .next_element.
I'm guessing your methods are returning NavigableString objects from
the parse tree. Those NavigableStrings have references (direct and
indirect) to every other part of the tree, so nothing gets freed.
To make sure the parse tree is freed, you'll need to remove the
NavigableString objects from the parse tree with .extract(), or
convert them into normal Python strings with unicode().