简体   繁体   English

我可以只强制收集某些类型的对象吗?

[英]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.

相关问题 我可以使用foreach仅从集合中返回某种类型吗? - Can I use foreach to return only a certain type from a collection? 强制用户仅键入comboBoxItems集合中包含的值 - Force the user to type-in only the values contained in the comboBoxItems Collection 计算集合中某种类型的对象,并将其用作文本框中的字符串 - count objects of a certain type in a collection and use this as a string in a textbox 通过在C#中的集合中包含某些对象来定义类型 - Define type by having certain objects in a collection in C# 将对象添加到集合中时,如何检查对象的类型 <T> ? - How can I check the type of an object when adding objects to a Collection<T>? 我如何强迫用户无法输入某点? - How do I force user to not be able to type past a certain point? 如何序列化SyndicationItem对象的集合? - How can I serialize a collection of SyndicationItem objects? 我可以在方法签名中强制使用匿名类型吗? - Can I force anonymous type in method signature? 如何限制组合框中的用户输入,以便您只能输入集合中的单词? - How do I limit user input in a combobox, So that u can only type words that are within the collection? 我可以告诉NHibernate不要保存某些对象吗? - Can I tell NHibernate not to save certain objects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM