freeing the memory of a casted object ?

Patricio Stegmann <[email protected]> Wed, 22 Jun 2011 19:18:57 -0300
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
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:
"""
import ctypes
import os
import sys
import time

if __name__ == '__main__':
    if sys.argv[1] == '0':
        cast_flag = False
    else:
        cast_flag = True
    while 1:
        print 'creating 1MB buffer'
        tmp_buffer = ctypes.create_string_buffer(10*1024*1024)
        if cast_flag:
            print 'casting it to c_void_p'
            tmp_pointer = ctypes.cast(tmp_buffer, ctypes.POINTER(ctypes.c_void_p))
        time.sleep(1)
"""

running:

python myscript.py 0

it will run without leaking

running:

python myscript.py 1

will leak more than 10MB at each cycle (seen with windows task manager or process explorer).

Can someone please give me a tip on how to free that memory ?
I really thank you for any tip !

Patricio

------------------------------------------------------------------------------
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