Is it a Bad Practice™ to omit FreeLibrary()?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Is it a Bad Practice™ to omit FreeLibrary()?

  1. #1
    Join Date
    Feb 2002
    Posts
    5

    Is it a Bad Practice™ to omit FreeLibrary()?

    I call LoadLibrary() several times on the same DLL (it's application specific and resides in a module directory) in order to get multiple instances of the DLL into application memory. Each instance will execute in it's own thread.

    Currently, rather than tracking each time the DLL is instantiated and maintaining the handle to each of those instances in order to call FreeLibrary() on each, the exe just relies on the ref count to drop to 0 when the application exits. Is this a safe assumption, or will some ill effect arise?


  2. #2
    Join Date
    Apr 1999
    Posts
    27,424

    Re: Is it a Bad Practice™ to omit FreeLibrary()?

    I think it's safe, since the DLLEntryPoint() with DLL_PROCESS_DETACH is called if the process is terminating or if FreeLibrary is called.

    About thread safety -- if your goal was to make the DLL thread-safe by putting it in its own thread, this will *not* make the DLL thread safe. The DLL has to be thread-safe internally, something you have to ask the creators of the DLL.

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    Feb 2002
    Posts
    5

    Re: Is it a Bad Practice™ to omit FreeLibrary()?

    Thanks.

    I had confirmed that my DllMain() had DLL_PROCESS_DETACH called, but I was unaware if there were any other ill effects cause by not explicitly calling FreeLibrary().

    Regarding thread safety, actually running the DLL on it's own thread to achieve thread safety wasn't my goal, but thanks for the advice. The intent behind each DLL in this application is to operate in a vacuum, making calls to the graphics driver for rendering 3D content to a rendering context. Putting each DLL on a separate thread allows me to prioritize said thread depending on what operation it's attempting, and how the balance of CPU usage versus GPU usage shifts with each operation.

    Regards,

    Alex Shows


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center