[New-bugs-announce] [issue44857] class member varibles assigned member functions create a circular reference

Cliff Cordeiro report at bugs.python.org
Fri Aug 6 22:20:59 EDT 2021


New submission from Cliff Cordeiro <cliff.cordeiro at gmail.com>:

This class is not collected by the gc without a custom __del__ method to del or assign None to self.fn:

import gc

class Leak:
    def __init__(self):
        self.fn = self.x

    def x(self):
        pass


gc.set_debug(gc.DEBUG_SAVEALL)

l = Leak()
del l
gc.collect()

for item in gc.garbage:
    print(item)

----------
components: Interpreter Core
messages: 399165
nosy: cliff.cordeiro
priority: normal
severity: normal
status: open
title: class member varibles assigned member functions create a circular reference
type: resource usage
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44857>
_______________________________________


More information about the New-bugs-announce mailing list