Manually prompting garbage collection

Fredrik Lundh fredrik at pythonware.com
Thu Jul 17 02:24:25 CEST 2008


Kyle Lanclos wrote:

> The DECREF decrements the reference count, but does not immediately prompt
> garbage collection when the reference count drops to zero; that garbage
> collection does not appear to occur until I return from the particular C
> function I am in the middle of executing.

Yeah, but what do you expect that garbage collection pass to result in? 
  What objects do you want to get rid of?  Do these objects have direct 
references to a resource that you're explicitly destroying from your C 
code?  Why?

 > Ideally, I want to explicitly prompt garbage collection in the middle
 > of a C function, without first returning to the larger Python
 > interpreter.

PyGC_Collect() does exactly that, so if that doesn't solve your problem, 
the only way to fix is this is to go back to the drawing board (and even 
if it would fix this, it's a good idea to get back to the drawing board 
anyway; Python's not C++, and code that relies on destructors to fire in 
a specific order, or before a specific event, is bound to fail sooner or 
later.)

</F>




More information about the Python-list mailing list