Re: LoadLibrary Question!
Quote:
When to use FreeLibrary?
Free it right after you use the extracted functions
Not to free it equals to a bad behavior to causing memory leaks
Re: LoadLibrary Question!
Loading library implies the dll code and data sections are mapped to your process address space, all import table entries resolved, global variables initialized and DllMain called.
Freeing library means the dll code and data sections appear unmapped. This means, in case you try to call previously linked export from the dll, you're gonna have access violation exception because of dereferencing address nonexistent to the moment. So, you need to free library only when you're sure all the dll functions are to be never called anymore, explicitly or implicitly.
Non-freeing library surely results in wasting address space, but I hardly can imagine how it may result in memory leak. 'Memory leak' situation is typically about losing a reference to memory fragment in a heap (of any kind, including CRT heap), and non-freed library has nothing common with a heap. And it hardly can be about handle leak, as long as loaded library handle can be quite easily restored by GetModuleHandle call.
Re: LoadLibrary Question!
Quote:
Originally Posted by
Igor Vartanov
Loading library implies the dll code and data sections are mapped to your process address space, all import table entries resolved, global variables initialized and DllMain called.
Freeing library means the dll code and data sections appear unmapped. This means, in case you try to call previously linked export from the dll, you're gonna have access violation exception because of dereferencing address nonexistent to the moment. So, you need to free library only when you're sure all the dll functions are to be never called anymore, explicitly or implicitly.
Non-freeing library surely results in wasting address space, but I hardly can imagine how it may result in memory leak. 'Memory leak' situation is typically about losing a reference to memory fragment in a heap (of any kind, including CRT heap), and non-freed library has nothing common with a heap. And it hardly can be about handle leak, as long as loaded library handle can be quite easily restored by GetModuleHandle call.
Your detailed explanation really unlocked my mind. Thank you very much!