Re: freeing the memory of a casted object ?

"Diez B. Roggisch" <[email protected]> Thu, 23 Jun 2011 09:05:41 +0200
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
 
On Jun 23, 2011, at 12:18 AM, Patricio Stegmann wrote:

> Hello to all,
> 
> I use intensively ctypes for wrapping lot of cdll's and love the module !
> However I face a painful problem of memory leak when I cast an object to something other.
> I post the following example which running on win32 is perfectly stable in memory when not casting, but leask 10MB per cycle when casting.
> I couldnt find help on the internet for this, nor found a free function on ctypes module or whatever.
> Please see and test if possible the following code:

Under OSX I see a similar behavior, so at first I thought you were right.

But you aren't!

Python uses GC, and that's just not kicking in. If you reduce the wait-time to a .1 (so the memory consumption grows much faster) you will see that it peaks - and then a great deal will be lost again.

Alternatively, you can do 

import gc


and then call gc.collect() every now and then. Then there should be no noticeable growth in mem-consumption.

But *don't* do this in real code unless you really have to. It just costs time. Let Python decide when to free memory.

Diez

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev

_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users