×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    what happens to TLS when DLL is unloaded?

    Suppose application is using DLL. Suppose object is allocated on the heap, and pointer to it is assigned to be TLS pointer for this DLL.

    1. when application closes, the system unloads any DLL being used by that application -- is that right?

    2. If so -- when it unloads DLL, does it automatically attempt to delete object in the DLL's TLS? If not, does that mean the object in TLS is orphaned when the DLL is unloaded, unless that object is explicitly free'd by code in the DLL during the closing sequence of application?

    3. if instead of application closing as intended, suppose instead leave occurs in DLL, but it is not TRAP'd until outside the application using the DLL. Suppose TRAP responds to leave by shutting down application in which leave occured -- so DLL is unloaded, and there is not opportunity to re-enter the DLL to execute clean-up code that frees object in TLS. So when DLL is unloaded in this manner, if TLS object is not otherwise automatically deleted, this would orphan object in TLS, right?

    4. If answer so far is: "when DLL is unloaded, object in TLS is not automatically deleted by system that unloads the DLL, regardless of why DLL is being unloaded" -- then to insure object in TLS is not orphaned, in addition to explicitly calling cleanup code in DLL to free object in TLS when application is closed as intentioned, it would also be necessary for this object in TLS to be pushed onto the cleanup stack so that it is also free'd in the event of leave causing closure of application to skip cleanup code. Is this correct?

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    17

    RE: what happens to TLS when DLL is unloaded?

    Normally the data pointed to by the TLS will have been allocated on the application heap - thus when the application ends, and the application heap is destroyed, the (possibly) orphaned data will be removed anyway, so it's not a problem.

Posting Permissions

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