This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amaury.forgeotdarc
Recipients amaury.forgeotdarc, darrenr, wplappert
Date 2008-12-03.09:53:02
SpamBayes Score 7.2217504e-06
Marked as misclassified No
Message-id <1228297984.45.0.482783144125.issue4273@psf.upfronthosting.co.za>
In-reply-to
Content
But the garbage collector was invented for this very purpose: to break
cycles! Take the following example which create a cycle for every
instance of the class (the profile module has similar code):

class C:
    def __init__(self):
        self.action = self.action_GO
        # cycle: the object's dict now contains a bound method 
        # which references the object
    def action_GO(self):
        print("GO")

This kind of construct is useful, and probably the best one in some
cases. Would you ban it from your code? from the python standard library?

Reference cycles are not bad at all, as long as they only hold memory:
they will be reclaimed when the systems needs more memory. 

I agree that they can be a problem for other valuable resource: opened
files, sockets, database cursors... even one thousand of uncollected
sockets are not enough to trigger a collection.
For this usage, I suggest that you iterate over gc.garbage, only warn
for such objects and remove all others (and after, clear gc.garbage and
run gc.collect() without the debug flag)
History
Date User Action Args
2008-12-03 09:53:04amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc, wplappert, darrenr
2008-12-03 09:53:04amaury.forgeotdarcsetmessageid: <1228297984.45.0.482783144125.issue4273@psf.upfronthosting.co.za>
2008-12-03 09:53:03amaury.forgeotdarclinkissue4273 messages
2008-12-03 09:53:02amaury.forgeotdarccreate