circular reference: canonical CPython approach please!
Thomas Wouters
thomas at xs4all.net
Thu May 4 16:44:50 EDT 2000
On Thu, May 04, 2000 at 10:28:44AM -0400, Warren Postma wrote:
> Has anyone written something like this:
> x = MyRedClassInstance();
> y = MyBlueClassInstance();
> x.y = shadow(y) # weak reference
> y.x = shadow(x) # weak reference
> When you del x, then y.x automatically becomes None, but otherwise, any
> other problems are avoided. Is that possible?
Not in Python, no. If you write shadow as a C extention, then yes, it's
possible to maek x.y and y.x refer to the other without incrementing its
refcount. However, it will not automatically 'undefine' the references when
the other goes away; doing that would require rewriting the rc-collector.
I dont know enough about the advantages of weak references to say wether
that's worth it -- I've never had any problem with avoiding circular
references in my code.
Python-programmers-shouldn't-read-up-on-perl-5.6.0-ly y'rs,
-- anyone notice how Perl adopted Python's number scheme ? --
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list