strange output from GC
Joe Wong
joewong at mango.cc
Thu Oct 7 04:38:46 EDT 2004
Hi, I am running some test script with garbage collector. Here is my test script:
import gc
gc.set_debug(gc.DEBUG_LEAK)
class bb:
def __init__(self):
self.i = 1123
self.functable = [{123:self.printit}]
def printit(self):
print self.i
try:
b = bb()
except:
pass
b=bb() # comment this out in 2nd test
print gc.collect()
print gc.garbage
It prints the following:
gc: collectable <dict 0083A540>
gc: collectable <bb instance at 0083B2D8>
gc: collectable <dict 0083A150>
gc: collectable <instancemethod 007E6EE0>
gc: collectable <list 00833810>
5
[{'i': 1123, 'functable': [{123: <bound method bb.printit of <__main__.bb instan
ce at 0x0083B2D8>>}]}, <__main__.bb instance at 0x0083B2D8>, {123: <bound method
bb.printit of <__main__.bb instance at 0x0083B2D8>>}, <bound method bb.printit
of <__main__.bb instance at 0x0083B2D8>>, [{123: <bound method bb.printit of <__
main__.bb instance at 0x0083B2D8>>}]]
Then, I comment out the line as stated in the script, I get:
0
[]
this time.
I done another test with the modified script:
import gc
gc.set_debug(gc.DEBUG_LEAK)
class bb:
def __init__(self):
self.i = 1123
self.functable = [{123:self.printit}]
def printit(self):
print self.i
b=bb()
del b
print gc.collect()
print gc.garbage
When I run, I got:
gc: collectable <dict 0083A540>
gc: collectable <bb instance at 0083B300>
gc: collectable <dict 0083A150>
gc: collectable <instancemethod 007E6EE0>
gc: collectable <list 00833810>
5
[{'i': 1123, 'functable': [{123: <bound method bb.printit of <__main__.bb instan
ce at 0x0083B300>>}]}, <__main__.bb instance at 0x0083B300>, {123: <bound method
bb.printit of <__main__.bb instance at 0x0083B300>>}, <bound method bb.printit
of <__main__.bb instance at 0x0083B300>>, [{123: <bound method bb.printit of <__
main__.bb instance at 0x0083B300>>}]]
If I remove the "del b" line from script, it outputs
0
[]
I don't know what is the problem with my script here. Are these the expected result from the garbage collector?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.773 / Virus Database: 520 - Release Date: 2004/10/5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20041007/fb539bbe/attachment.html>
More information about the Python-list
mailing list