On Feb 24, 2009, at 12:59 AM, Stefan Behnel wrote:

> Robert Bradshaw wrote:
>> On Feb 24, 2009, at 12:38 AM, Stefan Behnel wrote:
>>> http://trac.cython.org/cython_trac/ticket/218
>>
>> Note that the cleanup code is not (and cannot) always be safe across
>> multiple modules. When objects such as interned strings, numerical
>> literals, etc. are released, the module code becomes unsafe to use
>> (e.g. even a __del__ method of an object laying around somewhere  
>> else.)
>
> Hmm, we're in a ref-counted environment. Why would these objects be
> released when the module itself is still in use?


That is what the cleanup functions do--they try and release the  
memory in use by the module. The problem is that it isn't easy to  
tell when a module is still in use (as far as I can tell). It sounds  
like things have improved with Py3's unloading of modules.

A concrete example might help explain things. Say I have a Cython class

class A:
     def __del__(self):
         print 1

Now when this is compiled, a python int 1 will be created and stored  
in the module dictionary. If the module defining A is cleaned up  
before every instance of A is deallocated, then the cached Python 1  
will be collected and then at some later point A.__del__ could be  
called, which may result in a segfault.

- Robert


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to