How would I make garbage collection clean up RCW objects bound to an out-proc COM server?

我是研究僧i 提交于 2020-01-15 15:30:50

问题


I have a 64-bit .NET process that runs for days. The process consumes a native 32-bit COM server using DCOM. Once in a while the COM server runs out of memory because the .NET process garbage collector only sees the RCWs of the COM objects and those are quite lightweight and "not worth collecting". I need to somehow make garbage collector aware of those COM objects.

For the record, I tried to run the same code periodically force-starting garbage collection and the problem goes away so the problem is not a leak of some kind, just objects not collected fast enough.

Yes, I know there's GC.AddMemoryPressure() which allows to tell the garbage collector that we're now consuming more memory. The problem is the 64-bit .NET process may treat that as "not a big deal" - it's 64-bit and well, gigabyte here and another gigabyte there - "who cares" but the 32-bit process where the objects actually live is much more sensitive to those allocations.

So what may be a "no big deal" for a 64-bit process is surely a big deal for a 32-bit process and I need to somehow make the garbage collector of the 64-bit process be more sensitive to amount of memory used by another process.

How can I handle this situation so that the 64-bit process timely collects the RCWs and the 32-bit COM server doesn't run out of memory?

来源:https://stackoverflow.com/questions/29922000/how-would-i-make-garbage-collection-clean-up-rcw-objects-bound-to-an-out-proc-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!