[Stackless] Problem with memory deallocation

Kevin Kelley kelleyk at MIT.EDU
Thu May 22 11:01:09 CEST 2008


Hi all,

I'm having an issue with memory deallocation in Stackless.  I use an 
embedded interpreter and expose some classes to it.  I've noticed that 
the C++ destructor for exposed classes is usually called either when the 
Python object is garbage-collected or (if a reference to the object is 
kept around) when the Python interpreter is finalized.

However, with Stackless, I have noticed that when I create an object 
within a tasklet and keep a reference to it, if I later finalize the 
interpreter, the C++ destructor for the exposed class is never called.

Examples:

foo = exposed.ExposedClass( bar )
foo = None # destructor called

foo = exposed.ExposdClass( bar )
... script ends # destructor called

def uthread( ):
  foo = exposed.ExposedClass( bar )
  foo = None # destructor called
  while( True ):
    stackless.schedule( )
stackless.tasklet( uthread )( )
stackless.run( )

def uthread( ):
  foo = exposed.ExposedClass( bar ) # we just hold on to this reference 
until the script ends, and no destructor is ever called!
  while( True ):
    stackless.schedule( )
stackless.tasklet( uthread )( )
stackless.run( )

If it matters, my script signals to the enclosing application that it 
would like to terminate by throwing an 
"ApplicationTerminationException."  The exception is trapped in C++ and 
then Py_Finalize( ) is called.

I promise to do some playing around and see if I can figure out more 
specifically what conditions cause the destructor not to be called 
tomorrow, but if any of you have any wisdom, I would be very appreciative.

Thanks in advance,

Kevin




More information about the Stackless mailing list