On Fri, Mar 30, 2012 at 21:30, Benjamin Peterson <benjamin at python.org>wrote: > > + def test_cyclic_gc(self): > > + class ShowGC: > > + def __init__(self, flaglist): > > + self.flaglist = flaglist > > + def __del__(self): > > + self.flaglist.append(1) > > > I think a nicer way to check for cyclic collection is to take a > weakref to an object, call the GC, then check to make sure the weakref > is broken. > > > + > > + # Test the shortest cycle: lst->element->lst > > + fl = [] > > + lst = [ShowGC(fl)] > > + lst.append(ET.Element('joe', attr=lst)) > > + del lst > > + gc.collect() > > support.gc_collect() is preferable > > > + self.assertEqual(fl, [1]) > > + > > + # A longer cycle: lst->e->e2->lst > > + fl = [] > > + e = ET.Element('joe') > > + lst = [ShowGC(fl), e] > > + e2 = ET.SubElement(e, 'foo', attr=lst) > > + del lst, e, e2 > > + gc.collect() > > + self.assertEqual(fl, [1]) > > Thanks for the insights, Benjamin. I'll explore these alternatives and will submit a fix. Eli -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20120331/e51ff62b/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4