Win32 Subsystem Object Cleanup
ID: Q89290
|
The information in this article applies to:
-
Microsoft Win32 Software Development Kit (SDK) for Windows NT
SUMMARY
The Win32 subsystem guarantees that all Win32 objects owned by a
process will be freed when an application terminates. To accomplish
this, the Win32 subsystem keeps track of who owns these objects; it
also keeps a reference count. Reference counts are used when the
object is owned by more then one process. For example, a memory mapped
file can be used to provide interprocess communication, where more
than one process would own that object. The subsystem must make sure
that the reference count is zero before the object can be freed.
Freeing of Win32 objects can occur at different times. In general, it
occurs at process termination, but for some objects, it occurs at thread
termination.
NOTE: When running Win32-based applications with Windows 3.1 using the
Win32s environment, it is the responsibility of the Win32-based application
to ensure that all allocated GDI objects are deleted before the program
terminates. This is different from the behavior of the application with
Windows NT. With Windows NT, the GDI subsystem cleans up all orhphaned GDI
objects. Because there is no GDI subsystem with Windows 3.1, this behavior
is not supported.
MORE INFORMATION
At process or thread termination, the Win32 subsystem searches its lists to
find objects owned by this process or thread. Those that are owned by the
terminating process or thread and whose reference counts will be set to
zero when the process or thread is fully terminated will be freed.
The freeing of objects is slightly different for Win32-based applications
running under Win32s on Windows 3.1. The 16-bit objects (GDI objects,
windows, global memory, etc.) follow the same clean-up rules as Windows-
based applications do under Window 3.1. The 32-bit objects, such as memory
allocated via VirtualAlloc(), shared memory via mapped file I/O, 32-bit
modules, thunks allocated on the fly (for hook procedures, wndprocs etc.)
are all handled by Win32s and freed at process termination.
The following is a list of Win32 objects. Note that it may not be complete.
BASE: console, event, file (including file mapping), mutex,
semaphore, thread, process, pipe (including named pipes)
GDI: device context (DC), bitmap, pen, brush, font, region, palette
USER: window, cursor, icon, menu, accelerator table, desktop,
DDE communication objects, DDE conversation objects, dialog
Additional query words:
3.10 3.50 3.51 4.00
Keywords : SubSys
Version : NT:
Platform : NT
Issue type :