A C++ console application loads a DLL at run time using LoadLibrary() function and then calls some of the functions exported by the DLL. Once the application is done with the DLL, it calls FreeLibrary() function to unload the DLL. Will the memory leaks caused by the DLL function calls also get removed when the DLL is unloaded or they will remain there untill the application terminates?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- How to know full paths to DLL's from .csproj f
- thread_local variables initialization
相关文章
- vs2017wpf项目引用dll的路径不正确的问题
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- Why are memory addresses incremented by 4 in MIPS?
- What exactly do pointers store? (C++)
The memory leaks will remain. The OS doesn't care which DLL allocated the memory, it only cares about which process allocated the memory.
Alright! so here is how you could solve this problem. since its a console application I assume you are creating the application in that case the OS allocates stack/virtualmem and the heap for you where you would create the objects on heap. generally those details are abstracted from us as we simply use operator "new"!
here is what might work - get a handle to the deafault heap provided by your OS - GetProcessesHeap(); and free the heap after freelibrary using HeapFree()! this would clear the entire heap allocated to you but this might clear other dynamically allocated stuff as well.
this is how you can make it work- before loading the DLL create a private heap required for dynamic allocation of stuff from your DLL using - HeapCreate(). use HeapAlloc and HeapDealloc instead of new/delete to create objects from your dll with your private heap handle. free the heap using heapdestroy() once you are done with using the library!