Re: [Ctypes-devel] Crash using callback
Brought to you by:
theller
From: Thomas H. <th...@py...> - 2006-10-05 18:16:24
|
Peter Hansen schrieb: > Victor Stinner wrote: >> Question: would it be possible to change object lifetime, tell that the >> function keep a referrence of the object, or something like that? Or should I >> keep a copy of "mycallback = callback_t(mine)" somewhere? > > I'm pretty sure you must keep a reference in Python, or it will be (via > reference counting) freed up immediately. I'm also (slightly less, but > still fairly) sure that the documentation on callbacks points something > like this out... maybe double-check there again? > Peter is completely right. You need to keep the callback object alive *in Python* until it is no longer used by any C code. If ctypes would keep it alive forever automatically, we would have a memory leak. Thomas |