Software Archive
Read-only legacy content
17061 Discussions

DLL staying in memory

drpierce
Beginner
784 Views
I turned some computational code into a dll in order to call it from a VB interface. It works great. However, I call the dll multiple times. It stays resident in memory and variables retain their values from the first call. This is inheritied code from old programmers that didn't take the time to declare their variables. I would rather find a way to clear it out of memory than document every variable and re-initialize them all. I haven't been able to locate methods in either VB or Fortran to force the dll to clear.
0 Kudos
5 Replies
Steven_L_Intel1
Employee
784 Views
I don't know of a way to do this from VB - it is the one loading the DLL. All you can do on the Fortran side is add code to initialize the variables.

You'd have to convince VB to do an UnloadLibrary on the DLL, but that may cause VB to lose track of the DLL and cause more problems.

Steve
0 Kudos
Intel_C_Intel
Employee
784 Views
You could try creating a DLL middle-man that calls LoadLibrary, GetProcAddress, forwards the call, and calls FreeLibrary every time.

Your call as to where you want to spend your time, fixing the older code, or working around its 'issues' and the performance of your work-around.

hth,
John
0 Kudos
Steven_L_Intel1
Employee
784 Views
John, that's a wonderful suggestion! I wish I had thought of it the last couple of times we'd been asked this! I agree that fixing the code is a more appropriate solution, but yours isn't hard to implement.

Steve
0 Kudos
Intel_C_Intel
Employee
784 Views
Every now and then, I get a decent idea - or much more likely, remember someone else's idea :) ... that's probably the case here :)

-John
0 Kudos
Intel_C_Intel
Employee
784 Views
Hi John:

Granted, FreeLibrary ultimately reduces the usage count to zero and unmaps the library/module from the process. But does it warrant the near-instantaneous or otherwise deallocation of memory? IMO, it's usage is not a substitute for explicitly (re)initializing variables as required.

Best,
Gerry T.
0 Kudos
Reply