[python-win32] membuf and memory leaks

Robin Becker robin@jessikat.fsnet.co.uk
Tue, 10 Sep 2002 15:04:06 +0100


In message <2C1A673A677CD311988E00902773A6DD35CA9E@qbert.syscon-
computers.com>, Larry Bates <lbates@syscononline.com> writes
>I've recently been using Sam Rushing's calldll/membuf 
>functions to interface to several .DLL based toolkits.
>It has taken quite a bit of digging to get these working
>properly, but I finally have them working to my satisfaction.
>
>Today it occurred to me that while I'm allocating memory buffers
>in my class interface to the .DLL, I'm never releasing them.
>I'm concerned that over time I will be leaking memory to 
>every function call that must allocate a membuf.  I'm not 
>a C-programmer, but I looked over the source code to membuf
>function and there appears to be code there for deallocation
>of memory buffer (membuf_object_deallocate), but no entry 
>point to it in the membuf_object_methods list to access it.
>Can anyone shed some light on proper method for destroying
>membuf instances after they are no longer required so that
>I don't have a memory leak?
>
>Thanks in advance for any assistance.
>
>Regards,
>Larry Bates
>Syscon, Inc.

I think they get properly freed when they go out of scope. There's
certainly a destructor method set on the membuf object.

A simple test would be to put an allocation into a method or function
and then call it repeatedly several thousand times. Check with procexp
or task manager to see if the process size increases steadily.
-- 
Robin Becker