object deletion order question

howard at eegsoftware.com howard at eegsoftware.com
Wed Dec 20 20:13:40 CET 2000


While locating a crash in a Windows Python extension I am working on
    ( a Python wrap around a DirectX game library called CDX)
I discovered my problem as being the order in which Python objects
were being deleted.  

In this case, I had created a Sound object and a series of SoundBuffer
objects.  INSIDE DirectX, deleting the Sound object implicitly
releases the SoundBuffer objects.  When Python terminated (or at other
deletions), it called the delete method of the SoundBuffer  objects
after deleting the Sound objects, leaving DirectX calling into unknown
data space (I know..it's a Microsoft tradition).

I patched around this problem by managing a list of buffer objects
attached to a Sound object (explicitly specifying such objects) and
deleting them explicitly.

However, that led my to question:
        What ordering does Python use for object deletions? 

I somehow *assumed* that deletion was the reverse order of creation
(in a global sense) but clearly my problem was a case of
first-created, first-deleted.  Of course, I realize (now) I should not
have *assumed* ANY deletion order.  

For a "good" fix, I will probably have to build some linkage between
the two 'independent' classes in the C++ code rather than rely on
working around the problem in Python code.
Howard Lightstone
EEGSoftware
howard at eegsoftware.com



More information about the Python-list mailing list