freeing memory of ctypes python variables

Patricio Stegmann <[email protected]> Mon, 10 Jan 2011 17:31:13 -0200
Newsgroups gmane.comp.python.ctypes
Message-ID <[email protected]>
Hello to all,

I am looking for a way to free the memory of some variables on a ctypes wrapper I have.
I saw that if the code is using python variables, the python's gc should free the memory. So for example if I create a buffer (via ctypes.create_string_buffer(100*1024*1024)) and return from that function, python will free automagically that memory.

See the above example which works fine:

"""
import ctypes

def do_buffer():
    l__buf = ctypes.create_string_buffer(100*1024*1024)

def prompt_user():
    l__res = ''
    while l__res != 'x':
        do_buffer()
        l__res = raw_input('press x to exit or other to re-get mem')

if __name__ == '__main__':
    prompt_user()
"""

However if I create a pointer to that buffer, ctypes or python is not freeing the memory even after returning from the function. For example this new code never frees the memory:

"""
import ctypes

def do_buffer():
    l__buf = ctypes.create_string_buffer(100*1024*1024)
    l__podata = ctypes.cast(l__buf, ctypes.POINTER(ctypes.c_ubyte))

def prompt_user():
    l__res = ''
    while l__res != 'x':
        do_buffer()
        l__res = raw_input('press x to exit or other to re-get mem')

if __name__ == '__main__':
    prompt_user()
"""

I wonder how can I be able to free that buffer.
This is happening to me on Windows (xp pro), with python "Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32".

Thank you for any suggestion,

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl

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