Does this code create a circular reference ?

Ionel Simionescu ionel at
Tue Nov 30 13:57:00 EST 1999


I need advice on whether the situation described below introduces circular


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

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):

class headache:
  def method(self):
    a_child = child(self)


Thank you,

More information about the Python-list mailing list