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?