Share via


IsolationAwareCleanup function

You can call the IsolationAwareCleanup function to ensure that memory associated with a manifest in an ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID resource is freed reliably, and not leaked when the DLL or EXE that contains the manifest is loaded, unloaded, and reloaded.

Because this function is not inherently thread safe, you should always call it by using an explicitly thread-safe method, for example, calling it from the DllMain function when it receives the DLL_PROCESS_DETACH notification, or from code that exists in an EXE file. The IsolationAwareCleanup function can also prevent some invalid reports from leak detection tools.

If your manifest is in an ISOLATIONAWARE_MANIFEST_RESOURCE_ID resource, you can call IsolationAwareCleanup and it does nothing.

Note  After you call IsolationAwareCleanup, you must not call any functions that are affected by ISOLATION_AWARE_ENABLED. Affected functions include LoadLibrary, CreateWindow, all functions in Comctl32.dll, and all functions in Comdgl32.dll. Calling these functions after IsolationAwareCleanup results in undetermined effects that depend on an application.

 

Syntax

void IsolationAwareCleanup(void);

Parameters

This function has no parameters.

Return value

This function does not return a value.

Remarks

To provide a manifest as a resource in a DLL or EXE, you can compile the application with the -DISOLATION_AWARE_ENABLED flag, or add the following statement to the resource header.

#define ISOLATION_AWARE_ENABLED 1

If you add the statement, insert it before the following include statement.

#include "Windows.h"

Then you have a choice of the following two resource IDs for your manifest:

  • ISOLATIONAWARE_MANIFEST_RESOURCE_ID
  • ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID

If the resource ID for the manifest is ISOLATIONAWARE_MANIFEST_RESOURCE_ID, the loader can automatically resolve static dependencies of the manifest. During loading or unloading, the manifest is activated before calling the entry points of the DLL. The manifest can be queried using QueryActCtxW with dflag set to QUERY_ACT_CTX_FLAG_ACTCTX_IS_ADDRESS.

If there is no manifest in ISOLATIONAWARE_MANIFEST_RESOURCE_ID, side-by-side looks for a manifest in ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID. This manifest is never used by the loader. However, sometimes the memory that is associated with the manifest is not reliably freed and it is leaked. If the DLL or EXE is loaded, unloaded, and again loaded into a process, the memory that is associated with the manifest in a ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID resource is leaked. If the process ends and the DLL or EXE is then unloaded, the memory that is associated with the manifest is freed. However, some leak tracing tools may falsely report a leak.

You can call IsolationAwareCleanup by using a thread safe method to ensure that memory associated with a manifest in a ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID resource is reliably freed and not leaked when the DLL or is loaded, unloaded, and reloaded. IsolationAwareCleanup can also be called to prevent invalid reports of leaks by leak detection tools. After calling IsolationAwareCleanup, do not call functions that are affected by ISOLATION_AWARE_ENABLED.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Winbase.inl

See also

ACTCTX