Does this code create a circular reference ?
Ionel Simionescu
ionel at psy.uva.nl
Tue Nov 30 13:57:00 EST 1999
Hi,
I need advice on whether the situation described below introduces circular
references.
---
Basically, it is about a class that, within some method,
needs to create a temporary "child" object,
that is an object holding a reference to its "creator".
This is intended as a simple way to share access to certain variables known
by the parent.
I guess a danger in this approach, because the child,
even temporary, will be somehow stored in the locals dictionary of the
method.
I am not sure how it works and if it will cause trouble.
---
class child:
def __init__(self, parent):
self.parent = parent
def do_something(self):
pass
class headache:
def method(self):
a_child = child(self)
a_child.do_something()
---
Thank you,
ionel
More information about the Python-list
mailing list