-
-
Notifications
You must be signed in to change notification settings - Fork 661
Description
Following http://bugs.python.org/issue417795, we should probably only reference the dict weakly from the callback object to avoid unnecessary circular references.
As we found in #15367 comment:39, if an object C involved in a reference cycle becomes unreachable as a side effect of circular GC (e.g., a callback somewhere), the object C will only be collected by GC in the next round. A non-circularly referenced object C would have its reference count hit 0 and would be collected immediately. That is already a good reason to try and avoid circular references, even now that Python does clean them up eventually.
See also #13394 comment:19 (reasoning the validity of using a strongly referencing closure should be fine in theory -- this didn't take into account the practical consideration above).
CC: @simon-king-jena
Component: memleak
Author: Nils Bruin
Branch/Commit: u/SimonKing/ticket/15432 @ 13112a9
Reviewer: Simon King
Issue created by migration from https://trac.sagemath.org/ticket/15432