Add callback to avoid leaking weakrefs to iterators

The "live iterators" dict on DB instances keeps weakrefs, but while the
iterators pointed to by these weakrefs were released, the weakrefs
themselves were not. In older revisions, this cleanup was done by
WeakValueDictionary.