问题
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