This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: class member varibles assigned member functions create a circular reference
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: cliff.cordeiro
Priority: normal Keywords:

Created on 2021-08-07 02:20 by cliff.cordeiro, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg399165 - (view) Author: Cliff Cordeiro (cliff.cordeiro) Date: 2021-08-07 02:20
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)
msg399166 - (view) Author: Cliff Cordeiro (cliff.cordeiro) Date: 2021-08-07 02:34
It looks like the collector does detect the cycle and that's why it ends up in garbage with gc.DEBUG_SAVEALL set. Sorry about that.
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 89020
2021-08-07 02:34:55cliff.cordeirosetstatus: open -> closed
resolution: not a bug
messages: + msg399166

stage: resolved
2021-08-07 02:20:59cliff.cordeirocreate