Hi there!
I am attempting to use the WeakKeyHashMap to store a persistent tree data structure, where old nodes of the tree at some point disappear from the map if nobody refers to them any more.
It works well, except that .remove_expired() only removes one layer of nodes at a time: If a root is expired, it will remove root. But only on the next call to .remove_expired() will it remove the root's children. Et cetera.
(Actually, this is what sometimes happens, but depending on your hashing function the order in which we walk through the map changes and thus the order of removal changes. If the root ends up being removed before the children they are removed immediately but if it is not, they are not, etc.)
How to deal with this problem?