__del__ problem - would adopting Garbage Collection fix this?

Andrew Dalke dalke at acm.org
Thu Apr 20 23:14:34 EDT 2000


Neel Krishnaswami wrote:
> An even more sensible idea would be to drop __del__ methods
> altogether, since IMO you deserve to lose if you try to use
> the same deallocator for arbitrary resources that you use for
> memory, but that idea is probably not going to fly. ;)


Whenever this topic comes up, I bring out my case.  I've got
a Python wrapped interface to a C library.  The library also
works with FORTRAN, so stores a table mapping externally
exposed integer handles to internally used pointers.  In other
words, every object created is accessible, so even a C based
GC cannot delete all unused objects.  (At least to my rather
limited understanding of how automatic garbage collectors work
with non-cooperative C libraries.)

My wrapper code, however, does know when it's appropriate
to delete/free objects, and I've hooked that in using __del__.

This, BTW, is why my code doesn't work with JPython using a
JNI version of the C library instead of a SWIG one.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list