[Pythonmac-SIG] RefCount ?

Just van Rossum just@letterror.com
Sat, 1 May 1999 11:22:03 +0200


At 4:22 AM +0200 5/1/99, Peter Sommerfeld wrote:
>I have some objects which contain elements with direkt references
>back to the object. It would be possible to avoid any danger if I could
>decrement the refcount of the object at assignment. There is sys.getrefcount
>but is there somewhere it's counterpart, set refount ? This seems to be
>possible on C-level only. Or is there somewhere a hidden backdoor or dirty
>hack to accomplish this ?

You *really* don't want to do this.

Either provide a close() method that breaks the circular refs (which you'll
have to call explicitly) or reconsider your design: right now I'm working
on a fairly large library in which I prevent the problem by passing the
parent object as an extra argument to certain method calls. This works real
nice for me.

Although the circular references problem seems awkward, it kindof makes you
more aware of how your objects interact. It's not the first time my
*design* improved by trying use as few references as possible.

Disclaimer: I'm not an OO expert, so it may be all rubbish what I'm saying.

Just