作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
FullGC 通常会在运行时暂停所有线程。有两个 AppDomain,每个都运行多个线程。 GC 运行时,是所有线程都暂停,还是仅暂停其中一个 AppDomain 的线程?
最佳答案
很难回答,最好的办法就是测试一下:
using System;
using System.Reflection;
public class Program : MarshalByRefObject {
static void Main(string[] args) {
var dummy1 = new object();
var dom = AppDomain.CreateDomain("test");
var obj = (Program)dom.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(Program).FullName);
obj.Test();
Console.WriteLine("Primary appdomain, collection count = {0}, gen = {1}",
GC.CollectionCount(0), GC.GetGeneration(dummy1));
Console.ReadKey();
}
public void Test() {
var dummy2 = new object();
for (int test = 0; test < 3; ++test) {
GC.Collect();
GC.WaitForPendingFinalizers();
}
Console.WriteLine("In appdomain '{0}', collection count = {1}, gen = {2}",
AppDomain.CurrentDomain.FriendlyName, GC.CollectionCount(0),
GC.GetGeneration(dummy2));
}
}
In appdomain 'test', collection count = 3, gen = 2
Primary appdomain, collection count = 3, gen = 2
关于.net - 垃圾收集发生在进程级别还是应用程序域级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246167/
我是一名优秀的程序员,十分优秀!