Método Marshal.CleanupUnusedObjectsInCurrentContext ()
Notifica al tiempo de ejecución que debe limpiar todos los contenedores RCW (Runtime Callable Wrappers) asignados en el contexto actual.
Espacio de nombres: System.Runtime.InteropServices
Ensamblado: mscorlib (en mscorlib.dll)
Sintaxis
[SecurityCriticalAttribute]
public static void CleanupUnusedObjectsInCurrentContext()
public:
[SecurityCriticalAttribute]
static void CleanupUnusedObjectsInCurrentContext()
[<SecurityCriticalAttribute>]
static member CleanupUnusedObjectsInCurrentContext : unit -> unit
<SecurityCriticalAttribute>
Public Shared Sub CleanupUnusedObjectsInCurrentContext
Comentarios
The interop system pumps messages while it attempts to clean up RCWs. This ensures that cleanup for single-threaded apartment (STA) RCWs happens in all applications, including applications that do not pump often enough. However, some applications that do pump appropriately are very sensitive to where pumping occurs. When the interop system pumps messages in these applications, in places that are unexpected, , the application can encounter reentrancy issues that are difficult to diagnose. Therefore, applications need to be able to control their own pumping for a particular STA and to control the clean-up of RCWs.
However, developers often only control a subset of the threads in their application and thus cannot ensure that all threads are pumping appropriately.
To solve this problem:
Use the M:System.Threading.Thread.DisableComObjectEagerCleanup method to turn off automatic cleanup of RCWs, and the message pumping that occurs, on a per-thread basis. This allows developers to opt out of automatic clean-up, and the corresponding message pumping.
Use the M:System.Runtime.InteropServices.Marshal.CleanupUnusedObjectsInCurrentContext method to notify the runtime to clean up all RCWs that are allocated in the current context. This companion method allows developers to precisely control when the runtime performs cleanup in the current context.
Seguridad
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Información de versión
.NET Framework
Disponible desde 4.0
Ver también
Clase Marshal
Espacio de nombres System.Runtime.InteropServices
Volver al principio