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 pitrou
Recipients ocean-city, pitrou
Date 2009-01-12.12:21:41
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1231762902.14.0.443502484483.issue4921@psf.upfronthosting.co.za>
In-reply-to
Content
Since g calls "itself" in its own scope, it is stored as one of its own
cell vars, which creates a reference cycle. a is also part of its
reference cycle for the same reason, so it must wait for garbage
collection to be reclaimed.

If g didn't keep a reference to its cell vars, closures wouldn't be
possible, because the cell vars wouldn't survive the end of f's scope.

(g doesn't have to be recursive, it's enough that it makes a reference
to itself in its own scope:

def f():
    a = A()
    def g():
        a
        g

or even:

def f():
    a = A()
    def g():
        a
        h
    h = g

)
History
Date User Action Args
2009-03-09 14:33:58georg.brandlsetspambayes_score: 0.673817 -> 0.0
2009-01-12 12:21:42pitrousetrecipients: + pitrou, ocean-city
2009-01-12 12:21:42pitrousetmessageid: <1231762902.14.0.443502484483.issue4921@psf.upfronthosting.co.za>
2009-01-12 12:21:41pitroulinkissue4921 messages
2009-01-12 12:21:41pitroucreate