Issue 226254: Traceback objects not properly garbage-collected (original) (raw)

Created on 2000-12-19 01:50 by anonymous, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (6)
msg2702 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-12-19 01:50
System info: ============ Python 2.0 (#1, Dec 18 2000, 16:47:02) [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2 Linux phil 2.2.18 #1 Mon Dec 18 14:49:56 PST 2000 i686 unknown Sample code: ============ import sys class fooclass: def __init__(self): print 'CONSTRUCTED' def withtb(self, doit=0): try: raise "foo" except: if doit: tb = sys.exc_info()[2] def __del__(self): print 'DESTROYED' if __name__ == '__main__': foo = fooclass() if len(sys.argv) > 1: foo.withtb(1) else: foo.withtb(0) del foo How to reproduce: ================= Run the above python script: 1. Without any argument: the withtb() method exception handler does not retrieve any traceback object. The program prints `CONSTRUCTED' and `DESTROYED'. 2. With some arguments: the withtb() method exception handler retrieves a traceback object and stores it in the `tb' local variable. However `DESTROYED' never gets printed out. I think that the `foo' object will never be garbage collected anymore. Workaround: =========== Deleting the `tb' object seems to restore things: if doit: tb = sys.exc_info()[2] del tb Other: ====== I've found this problem also in python 1.5.2 and python 1.6. Possible cause: =============== I would tend to think that we're creating a circular loop which cannot be garbage collected: - `tb' holds a reference to the traceback object - the traceback object holds a reference to the local scope - the local scope holds a reference to the `tb' variable The only way out is to break the circular reference by hand, although it's annoying. Phil - phil@commerceflow.com.
msg2703 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-12-19 04:21
This is not a bug. Saving the traceback as a local variable creates a circular reference that prevents garbage collection. If you don't understand this answer, please write help@python.org.
msg2704 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-12-21 02:49
Could I know why this was deemed to be `Invalid' ? Phil - phil@commerceflow.com.
msg2705 - (view) Author: Nobody/Anonymous (nobody) Date: 2000-12-21 02:50
oops, didn't see you comment. Forget about my question... Phil - phil@commerceflow.com.
msg2706 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2000-12-21 02:59
"Invalid" is a just a word -- it comes with SF bug system and isn't defined anywhere. By convention, we pair Not-A-Bug with Invalid, for lack of something better to do. Not-A-Bug means it's not a bug : you may not like the answer, but Guido is saying it's functioning as designed and he has no plans to change that.
msg2707 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-12-27 22:21
Note that the bug report was about 1.5.2 and 1.6. This should be fixed by the cycle collection in 2.0, shouldn't it?
History
Date User Action Args
2022-04-10 16:03:34 admin set github: 33610
2000-12-19 01:50:28 anonymous create