该图片中的[垃圾收集]是什么意思?还有“20个电话”的东西?

我的意思是,我怎么知道为什么GC花了这么长时间?它收集了很多小 object 吗?一个大的?关于如何优化这一点的任何提示?

有问题的代码是:

private void DeserializeFrom(SerializationInfo info)
{
    Width = info.GetInt32("width");
    Height = info.GetInt32("height");
    var data = (List<byte>)info.GetValue("cells", typeof(List<byte>));
    cells = new Cell[physicalSize.Width, physicalSize.Height];
    int pos = 0;
    for (int x = 0; x < physicalSize.Width; x++)
    {
        for (int y = 0; y < physicalSize.Height; y++)
        {
            cells[x, y] = new Cell();
            if (x < Width && y < Height)
            {
                cells[x, y].HasCar = data[pos];
                pos++;
            }
        }
    }
}

没什么好看的。我怀疑罪魁祸首是大List<byte>对象,但我认为收集单个大对象应该是即时的(与收集一堆小对象相对)。

最佳答案

如果要找出导致GC的原因,正在分配和收集哪些对象,可以通过dotMemory进行操作。这是一个说明如何优化内存流量的教程:https://confluence.jetbrains.com/display/NETCOM/Tutorial+3+-+How+to+Optimize+Memory+Traffic+with+dotMemory

关于.net - [垃圾收集] dotTrace Performance Profiler是什么意思?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3618322/

10-08 23:16