Reputation: 803
My application is a C# program that uses C ++ functions over P/Invoke. Before calling a C ++ function the library is loaded:
IntPtr hLib = LoadLibrary("CPPFunctions.DLL");
and after the C++ function returned it's results over a callback to my C# Application the library gets cleaned up:
FreeLibrary(hLib);
A library that is used within C++ is storing memory, but never releases it. This is because the library is a simulation model whose process is usually terminated after a run.
This means that I will need more and more memory if the function is called repeatedly.
Is there a way to completely free the memory allocated by C++?
Upvotes: 2
Views: 361
Reputation: 613013
This isn't something that you can do from the outside. The library must provide facilities to enable this. Either the library has been badly designed and leaks unavoidably, or you are failing to call the cleanup functions that it provides.
Either way, there is no magic pinvoke function that can solve this problem. The way forward will be found by studying the library and its documentation. You may need to get in touch with its developer.
Upvotes: 3