博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AreComObjectsAvailableForCleanup and CleanupUnusedObjectsInCurrentContext
阅读量:5875 次
发布时间:2019-06-19

本文共 2156 字,大约阅读时间需要 7 分钟。

AreComObjectsAvailableForCleanup

()

Indicates whether runtime callable wrappers (RCWs) from any context are available for cleanup.

Remarks

If there are a lot of references between managed and native code with deep dependency graphs it can take a long time for all the objects to clean up.Each time a GC runs it will free up some number of RCWs, which will in turn release the underlying COM objects.Those COM objects will then release their managed references and make more objects available for cleanup the next time a GC runs, which starts the process over again.

The AreComObjectsAvailableForCleanup method provides a way for the application to determine how many cycles of GC.Collect and GC.WaitForPendingFinalizers need to happen in order to clean everything up.

Marshal.CleanupUnusedObjectsInCurrentContext

()

Notifies the runtime to clean up all (RCWs) allocated in the current context.

Remarks

 

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:

 

  1. Use the 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.

  2. Use the 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.

 

 

转载地址:http://ibzix.baihongyu.com/

你可能感兴趣的文章
MYSQL查询一周内的数据(最近7天的)
查看>>
Redis的缓存策略和主键失效机制
查看>>
禁止body滚动允许div滚动防微信露底
查看>>
Xtreme8.0 - Kabloom dp
查看>>
jquery css3问卷答题卡翻页动画效果
查看>>
MDK5.00中*** error 65: access violation at 0xFFFFFFFC : no 'write' permission的一种解决方法
查看>>
Android 集成支付宝支付详解
查看>>
SQL分布式查询、跨数据库查询
查看>>
C#------连接SQLServer和MySQL字符串
查看>>
Arcgis Licensemanager 不能启动的原因之一(转载)
查看>>
(原)Android在子线程用handler发送的消息,主线程是怎么loop到的?
查看>>
$digest already in progress 解决办法——续
查看>>
虚拟机 centos设置代理上网
查看>>
Struts2中Date日期转换的问题
查看>>
mysql 数据类型
查看>>
Ubuntu 设置当前用户sudo免密码
查看>>
设置tomcat远程debug
查看>>
android 电池(一):锂电池基本原理篇【转】
查看>>
Total Command 常用快捷键
查看>>
ionic 调用手机的打电话功能
查看>>