[ python-Bugs-1553819 ] Class instance apparently not destructed when expected
SourceForge.net
noreply at sourceforge.net
Thu Sep 7 09:19:57 CEST 2006
Bugs item #1553819, was opened at 2006-09-06 20:26
Message generated for change (Comment added) made by nnorwitz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1553819&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Peter Donis (peterdonis)
Assigned to: Nobody/Anonymous (nobody)
Summary: Class instance apparently not destructed when expected
Initial Comment:
When an instance variable of a class with the same
name as a class variable in a base class is assigned
a value (making the class variable of the base class
invisible), the class instance does not appear to be
destructed when it should.
Here is the simplest test script I've been able to
come up with that reproduces the error, along with
its output when run from a shell prompt. I've
included the dir() commands to make sure that the
variable referencing the class instance is in fact
deleted in both cases. As you can see, the instance
of the base class gets destructed as expected, but
the instance of the derived class does not.
--- Test script ---
#!/usr/bin/env python
# Test script to see when objects are freed
class Test(object):
testfield = None
def __init__(self):
print "Initializing test object."
def __del__(self):
print "Freeing test object."
class Test2(Test):
def __init__(self):
# This masks Test.testfield
self.testfield = self.meth
Test.__init__(self)
def meth(self):
pass
print dir()
t = Test()
print dir()
del t
print dir()
t2 = Test2()
print dir()
del t2
print dir()
--- Output ---
$ python deltest.py
['Test', 'Test2', '__builtins__', '__doc__', '__file__', '__name__', 'func']
Initializing test object.
['Test', 'Test2', '__builtins__', '__doc__', '__file__', '__name__', 'func', 't']
Freeing test object.
['Test', 'Test2', '__builtins__', '__doc__', '__file__', '__name__', 'func']
Initializing test object.
['Test', 'Test2', '__builtins__', '__doc__', '__file__', '__name__', 'func', 't2']
['Test', 'Test2', '__builtins__', '__doc__', '__file__', '__name__', 'func']
----------------------------------------------------------------------
>Comment By: Neal Norwitz (nnorwitz)
Date: 2006-09-07 00:19
Message:
Logged In: YES
user_id=33168
The attached variant puts this into a function and shows ref
leaks. It requires a debug build.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1553819&group_id=5470
More information about the Python-bugs-list
mailing list