memory leaks with ctypes LoadLibrary ?

C

chris

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

Thomas Heller

chris said:
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
 
T

Thomas Heller

chris said:
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
 
C

Chris Grebeldinger

So, am I misinterpreting what gc.collect is printing, and there is
actually no memory leak?

Or if I'm not and there actually is a problem, Is there a better way to
use ctypes so that I don't have to modify the module?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top