In GitLab by @urbanmatthias on Aug 22, 2019, 12:54
For all wrapper sessions, the wrapper is the only root of the datastructure.
The prune() method usually removes all Elements that are not reachable from the root.
The CoreSession on the other hand can have multiple roots.
It is not obvious which roots to consider when testing for reachability.
It is not obvious, which elements should be deleted from the registry.
We considered the following options:
Option 1
Let the user specify the roots when calling prune.
The interface of the CoreSession.prune() will then be different to prune() of WrapperSession()
This is not very intuitive.
Option 2
Use the garbage_collector.get_referrers() method to check if the user still uses a cuds object.
Unfortunately, the documentation states that this method should only be used for Debugging.
Option 3
Make use of weak references.
Simply converting the registry to a WeakValueDictionary will not work.
Other cuds do not reference their neighbors by strong references.
Instead they are referenced by uid.
Option 3.1
We could maintain a set of uid (copies) of cuds objects, that are referenced by the user.
This set is a WeakSet.
The garbage collector deletes a uid-copy if no reference to that uid-copy exists.
The cuds-objects the user creates and deals with contains a reference to its-uid copy.
In the registry, no references to these copies must be stored.
That way, the garbage collecter will delete the uids in the WeakSet, if the user has no reference to the respective object.
To realize this, the user has to work with objects, that wrap the real cuds objects.
These wrapped objects contain the references to the uid-copies in the weak set.
The registry only stores the real cuds without the references.
--> We can use the uids in the weak set as roots for prune()
Too much effort?