You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A closed __namespace__ stream subclass in a reference cycle is never freed #186
With the fix for #169 (#176), an instance of a __namespace__ subclass is never freed when all of these are true:
its .NET base class suppresses its own finalizer on Close() or Dispose(), as MemoryStream does
the instance is part of a Python reference cycle, such as s.me = s
it is closed and then dropped
The fix for #169 gives the .NET object one reference to the Python object, and the generated .NET finalizer releases it. A suppressed finalizer never runs, so the reference is never released and everything the instance holds stays alive.
class S(MemoryStream) with __namespace__, 10 instances with s.me = s and s.payload = Payload() (a plain Python class). Call s.Close() and drop each one. After running both collectors and draining the finalizer queue:
Unreferenced cycles of __namespace__ instances now wait for a .NET GC before they are freed. In the same review, 6,000 throwaway self-cycles holding 64 KiB each retained about 395 MB with #176 and about 8 MB on master, with no .NET GC on either. Both dropped to the same level once both collectors ran.
Priority
Low. It needs a __namespace__ subclass of a disposable .NET type that is kept in a reference cycle, which is not code algorithm authors normally write. It was left out of #176 on purpose to keep that fix within the scope of #169, and it is listed there as a known limit.
Activity
Keep only the __del__ assignment and .NET owner handoff fixes