[New-bugs-announce] [issue4921] Object lifetime and inner recursive function

Hirokazu Yamamoto report at bugs.python.org
Mon Jan 12 12:19:17 CET 2009


New submission from Hirokazu Yamamoto <ocean-city at m2.ccsnet.ne.jp>:

Hello. Sorry if this is noise. I expected

__del__
out of function
__del__
out of function
__del__
out of function

on following code, but actually I got

out of function
out of function
out of function
__del__
__del__
__del__

Is this expected behavoir? (I believed `a' would be
freed after returned from f(), so I was suprised)

If I remove the comment of gc.collect(), the code works as expected.

///////////////////////////////

import gc

class A:
    def __del__(self):
        print("__del__")

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

def main():
    for _ in range(3):
        f()
#       gc.collect()
        print("out of function")

if __name__ == '__main__':
    main()

----------
components: Interpreter Core
messages: 79664
nosy: ocean-city
severity: normal
status: open
title: Object lifetime and inner recursive function
versions: Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4921>
_______________________________________


More information about the New-bugs-announce mailing list