Commit 15928944 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Try again to make weakref1 more robust

parent 59479580
import weakref
import gc
num_destroyed = 0
def cb(wr):
print "object was destroyed", wr()
global num_destroyed
num_destroyed += 1
def doStuff():
def meth():
......@@ -11,18 +13,7 @@ def doStuff():
wr = weakref.ref(meth, cb)
return wr
def fact(n):
if n <= 1:
return n
return n * fact(n-1)
w = doStuff()
fact(10) # try to clear some memory
def recurse(f, n):
if n:
return recurse(f, n - 1)
return f()
recurse(gc.collect, 50)
l = [doStuff() for i in xrange(5)]
gc.collect()
assert num_destroyed >= 1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment