Re: freeing memory of ctypes python variables
Thomas Stover <[email protected]> Tue, 11 Jan 2011 11:21:34 -0600
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
> From: Patricio Stegmann <[email protected]> ... > 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() > """ Do you mean it always keeps at least one buffer, or every call to do_buffer() allocates a new one that never goes away? Could it be explained by a memory pool in the gc? It does seems like I remember something about the python object create_string_buffer() has an extra reference count. -- www.thomasstover.com NO CARRIER ------------------------------------------------------------------------------ Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl