[issue4921] Object lifetime and inner recursive function

2018-09-11 Thread Eric Snow


Change by Eric Snow :


--
nosy: +eric.snow

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2018-09-10 Thread Eric Wieser


Eric Wieser  added the comment:

For anyone doing archaeology - this came up on python-dev about a year after 
this issue was filed: 
https://mail.python.org/pipermail/python-dev/2009-December/094439.html

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2018-02-19 Thread Eric Wieser

Eric Wieser  added the comment:

Would it be possible for function self-reference cell vars to be weak 
references?

This wouldn't solve the issue for co-recursive inner functions, but would at 
least prevent reference cycles for the more common case of simple recursive 
functions.

--
nosy: +Eric.Wieser

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2009-01-12 Thread Hirokazu Yamamoto

New submission from Hirokazu Yamamoto ocean-c...@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 rep...@bugs.python.org
http://bugs.python.org/issue4921
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2009-01-12 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

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

)

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4921
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2009-01-12 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

Thank you for explanation. The combination of inner function + method 
variable was very handy for me, but maybe I should refrain from using 
it lightly. :-(

--
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4921
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2009-01-12 Thread Hirokazu Yamamoto

Hirokazu Yamamoto ocean-c...@m2.ccsnet.ne.jp added the comment:

A little followup. Attached script q112.py (some puzzle program) ate up 
my RAM (80MB) and never ran GC while solving. Current python GC looks 
at the number of GC objects, but GC object like set object can contain 
many non GC object, so... I feel it would be nice if there is better GC 
triger/timing.

Added file: http://bugs.python.org/file12704/q112.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4921
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4921] Object lifetime and inner recursive function

2009-01-12 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Well, tracking memory consumption of each container would be better than
simpling couting them, but it's much more complicated as well (not to
mention that memory consumption can vary, so you must recalculate it
periodically...).

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4921
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com