Does the P / Invoke DLL execute and then close it?

If I use C # for P / Invoke for a specific DLL, will the actual C ++ DLL be executed for the duration of the call and then be turned off, destroying all the memory used? Or will .NET take charge of the memory used by the C ++ DLL in the unmanaged heap and give pointers to these objects in the C ++ DLL every time I call a static function?

When I need a specific C ++ project to maintain persistent memory, do I have to create an ActiveX / COM server so that its memory is saved, and still be able to call it with C #?

+7
source share
2 answers

If I use C # for P / Invoke for a specific DLL, will the actual C ++ DLL be executed for the duration of the call and then be turned off, destroying all the memory used?

Not. Once the DLL loads, it will remain loaded. DLL lifetime is not tied to a function call. This means that variables in a DLL that have static storage are stored outside the initial p / invoke call.

+5
source

If you create an object from a C ++ - DLL, it will remain until you delete it or, rather, destroy it. Since you need to manually delete unmanaged objects, it will remain.

+2
source

All Articles