贾里德的回答当然很棒。添加其他几点:
运行 GC.Collect() 真的可以降低它很快运行的概率吗?
是的。
这是使用 .net 框架执行此操作的正确方法吗?
I would not want the correctness of software that has human-life-safety-critical functions to depend on probabalistic guesses about the undocumented behaviour of the collector.
That said: you should do a WaitForPendingFinalizers after the collection. Remember, finalizers run on their own thread, and that might be taking up processor time.
Does GC.Collect() collect for other CLR programs too or is it only applicable to the current process?
Collecting cleans up managed memory in the current process, so if you have multiple appdomains in one process, collecting in one appdomain collects in the others. It does not go cross process.