dll memory leak troubles

dll memory leak troubles

Post by tohellwith » Tue, 06 Apr 2004 23:16:44


Hi all,
I bought a MSI geforcefx 5600 128 graphics card a few months back. The
thing came with a remote control which I thought would be handy but
the software it came with is rubbish. I was however able to download
some dlls from the MSI homepage and a small visual c++ 6 windows app.
This app was also rubbish but using it I was able to copy paste a
wrapper dll together which I can load and use in c#. The only
functions I know of, that I can access from the dll are initialize()
and read(). My app basically initializes the dll and then every 100 ms
or so calls the read() function to check if a button is being pressed.
The problem is that every time read() is called some memory is
allocated and never gets released. I'm pretty sure my code is ok and
the problem is with one of the 4(a bit excessive i thought) other dlls
it uses. what I was wondering is if theres someway of periodically
releasing all the memory used by the dll and then reloading it (messy
I know) or if anyone maybe has another solution(bearing in mind my
programming abilities are of the monkey see monkey do level) I tried
adding a function to my wrapper dll that calls freelibrary on the msi
dll but it did diddly squat.
Thanks in advance
 
 
 

dll memory leak troubles

Post by dverm » Wed, 21 Apr 2004 06:36:14

Hi!

This isn't really a VS De *** issue, but let me answer nevertheless. :)

The way I see it, you are consuming a dll provided by the company in your
C# Exe. I do not think there is any way for you to clean up the memory used
by the dll as long as the dll is used, because you do not have access to
the dll's internals, and we don't know how the dll code is using the
memory. It could be a global variable in the dll that the dll just keeps
using.

The only thing I would suggest is unloading the dll & reloading it in your
exe, which should unallocate the memory used by the dll.

Alternately, you could call up the company's customer support and tell them
of the problem you are having with their dll.

Regards,
D.V.

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.yqcomputer.com/

 
 
 

dll memory leak troubles

Post by tohellwith » Thu, 22 Apr 2004 18:57:36

Thanks for the reply anyway. I kinda figured as much :( just hoped,
you know the way. I contacted them, and they told me they didn't
encounter any memory leak with their dll. (even though I saw the same
problem with the test app they supplied!) I'm guessing they just
didn't test on very many platforms or something :(
 
 
 

dll memory leak troubles

Post by dverm » Fri, 23 Apr 2004 06:13:58

Hmmm... well I guess you should use the dll unload/reload technique to
clean up the memory, though doing this all the time could lower the perf of
your exe. You could unload & reload periodically say after 2000 calls to
the dll.

I don't think the memory leak is a platform issue - you need to de-allocate
memory you are using by yourself on any platform, otherwise it stays there
until the module exits.

Regards,
D.V.
 
 
 

dll memory leak troubles

Post by Pavel Lebe » Fri, 23 Apr 2004 12:05:13


of
de-allocate

Unloading a dll does not guarantee that all memory allocated by this
dll will be freed.

For example, allocations made with LocalAlloc/GlobalAlloc, VirtualAlloc
or new/malloc (when using dll version of CRT) will not be freed.
 
 
 

dll memory leak troubles

Post by dverm » Sat, 24 Apr 2004 07:00:05

Well it is the best he can do under the circumstances, given that there is
no source and no prospect of re-building the dll with better memory cleanup
in place.

If there is a better way, I would be happy to learn it :)

Regards,
D.V.

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.yqcomputer.com/
 
 
 

dll memory leak troubles

Post by Pavel Lebe » Sat, 24 Apr 2004 10:38:47

A better way would be to load this dll into a sacrificial process
that is killed after a certain number of calls, or when its memory
usage gets above a certain threshold (kind of like what COM+
on W2K3 does).



cleanup
 
 
 

dll memory leak troubles

Post by tohellwith » Tue, 27 Apr 2004 21:55:57

Sorry for the late reply, I had assumed the thread was dead and I
forgot all about it. What you're suggesting is that I have 2 apps, one
always on which accesses the dll through a second app/service which I
can run and destroy periodically? Or did you have something more
elegant in mind.
Thanks for all the replies anyway though, I'm pretty sure I can hack
some sort of solution together from yer advice as is.

Ps: I've since gotten my remote control moving the mouse pointer and
simulating mouse clicks now which is exactly what I wanted so if the
solutions turn out to be very messy I might just sweep the leak under
the carpet and try to forget about it (though it feels wrong even
typing that :-)
 
 
 

dll memory leak troubles

Post by Pavel Lebe » Thu, 29 Apr 2004 10:19:37


Yes.