[issue44857] class member varibles assigned member functions create a circular reference

2021-08-06 Thread Cliff Cordeiro


New submission from Cliff Cordeiro :

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 
<https://bugs.python.org/issue44857>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44857] class member varibles assigned member functions create a circular reference

2021-08-06 Thread Cliff Cordeiro


Cliff Cordeiro  added the comment:

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.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue44857>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com