[英]Can I force collection for objects of certain type only?
I have a problem with RCWs not being timely collected . 我对未及时收集RCW有问题 。 I think of periodically force-starting garbage collection from inside code.
我想到从代码内部定期强制启动垃圾收集。 However I'm not sure if that will have some undesired slowdown.
但是我不确定这是否会导致一些不希望的减速。
I'm not actually interested in collecting all objects, I only need RCWs collected and they all have System.__ComObject
type. 我实际上对收集所有对象不感兴趣,我只需要收集RCW,它们都具有
System.__ComObject
类型。 I guess that collecting only them would be faster. 我想只收集它们会更快。
Is it possible to force garbage collection for objects of certain type only? 是否可以仅对某些类型的对象强制进行垃圾回收?
No, It's not possible, you can only force a garbage collector to run but you can not force it to work according to your logic. 不,这是不可能的,您只能强制垃圾收集器运行,而不能强制其根据逻辑运行。
For more information on garbage collector please read this: https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110).aspx 有关垃圾收集器的更多信息,请阅读: https : //msdn.microsoft.com/zh-cn/library/ee787088(v=vs.110).aspx
Also GC is a static class, we can't override any of it's method :( 另外GC是一个静态类,我们不能覆盖它的任何方法:(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.