Commit 189d3b8c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix weakrefs on large objects

We would keep on adding the same object to the weakrefs list,
which would eventually trigger a collection, and cause all sorts
of weird things to happen.
parent 50e8fd65
......@@ -95,12 +95,13 @@ inline void sweepList(ListT* head, std::list<Box*, StlCompatAllocator<Box*>>& we
cur = cur->next;
} else {
if (_doFree(al, &weakly_referenced)) {
removeFromLL(cur);
auto to_free = cur;
cur = cur->next;
free_func(to_free);
} else {
cur = cur->next;
}
}
}
......
import weakref
import gc
def doStuff():
def meth():
......@@ -16,5 +15,18 @@ def fact(n):
w = doStuff()
print fact(10) # try to clear some memory
# Try creating a large object to make sure we can handle them:
def f():
class C(object):
# Adding a __slots__ directive increases the size of the type object:
__slots__ = ['a' + str(i) for i in xrange(1000)]
return weakref.ref(C)
r = f()
import gc
gc.collect()
print w()
assert r() is None, "object was not collected"
assert w() is None, "object was not collected"
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