Using C Dll on vb.net and memory

birdofprey

New member
Joined
Sep 10, 2006
Messages
2
Programming Experience
3-5
Hi all!
I've made an app in vb.net that needs a dll to execute some crypt/decrypt routines with openssl library that I also coded in VC++, to get some speed.
The functions on this dll need to be accessed thousand of times during the program execution and work well.
The problem is the memory it uses, after about 100000 access to a specific routine on the dll that returns a string, the program memory used by the app, shown on task manager is HUGE about 200Mb and more if I let it running longer.
So I tried to find out if the problem was on memory release on dll or on vb.net app, and coded a simple app which follows:

The code on the dll:
VB.NET:
extern "C" __declspec(dllexport)char *Do_Nothing(char *data1){
return data1;
}

The code on the vb app:
VB.NET:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hLib As Integer = LoadLibrary(dllPath)
    End Sub

    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim data As String = "1234568716327138719827398217398273917129739127329173219873218979879217397981273"
        txt1.Text=Do_Nothing(data)
       data=Nothing
    End Sub

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       FreeLibrary(hLib) 'release library
      hLib=Nothing
    End Sub
and found out that whenever I press the button 2 the memory increases about 20 bytes.
Of course, after a few thousand times of using the routine the memory usage grows to those huge numbers....:(
When i press button 3 it just won't release it either.
The program size on memory stays the same:(
The problem, I think, it's got to do with the string return from dll, and the memory it uses, but i'm not sure.

Can anyone help me on this?
Best Regards
birdofprey
 
Doesn't look like you use FreeLibrary on the right hLib handle.
 
Even if you did declare it 'public' you also declared it locally when you did Loadlibrary, as in posted code.
 
Back
Top