memory leaks with ctypes LoadLibrary ?

Thomas Heller theller at python.net
Tue Mar 1 15:37:36 EST 2005


"chris" <cgrebeld at gmail.com> writes:

> What is the proper way to use ctypes to access an exported Function in
> a dll file on windows?  I must be missing something because I get
> memory leaks when I  use it:
>
> import ctypes
> import gc
>
> gc.enable()
> gc.set_debug(gc.DEBUG_LEAK)
> lib = ctypes.windll.LoadLibrary("H:\lib\mylib.dll")
> fn = lib.myfn
> fn("test")
> del fn
> del lib
> gc.collect()
> gc: uncollectable <WinDLL instance at 015DFFA8>
> gc: uncollectable <dict 015D9420>
> gc: uncollectable <_StdcallFuncPtr 015DAE48>
> gc: uncollectable <list 014E2030>
> 4
>
> What am I doing wrong?

Nothing ;-) You could delete or comment out the __del__ method of class
CDLL, in the file ctypes/__init__.py.

Thomas



More information about the Python-list mailing list