What does [Garbage collection] mean in this pic? And the "20 calls" thing?
在这张图中[垃圾收集]是什么意思?那“20次通话”呢?
I mean, how can I figure out why GC took so long? Was it collecting a lot of small objects? A single big one? Any hints as to how to optimize this at all?
我的意思是,我怎么知道为什么GC花费这么长时间?它收集了很多小物件吗?一个大吗?任何关于如何优化这个的提示?
The code in question is:
所涉及的守则是:
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++;
}
}
}
}
Nothing too fancy. I suspect the culprit is the big List<byte>
object, but I thought collecting a single, big object is supposed to be instant (as opposed to collecting a bunch of small objects).
没有什么太复杂。我怀疑罪魁祸首是大列表
2 个解决方案
#1
2
If you want to find out what is causing GCs, what objects are being allocated and collected, you can do it via dotMemory. Here is a tutorial that explains how to optimize memory traffic: https://confluence.jetbrains.com/display/NETCOM/Tutorial+3+-+How+to+Optimize+Memory+Traffic+with+dotMemory
如果您想知道是什么导致GCs,什么对象被分配和收集,您可以通过dotMemory来完成。这里有一篇教程,解释如何优化内存流量:https://confluence.jetbrains.com/display/NETCOM/Tutorial+3+-+ how +to+ optimization +内存+流量+with+dotMemory
#2
1
A little late to the party but if you are using .Net then you are using managed code, which basically means that the .Net runtime disposes your objects accordingly so you don't have memory leaks as opposed to C or C++.
有点晚了,但是如果你在使用。net,那么你在使用托管代码,这基本上意味着。net运行时相应地处理你的对象,这样你就不会有内存泄漏,而不是C或c++。
Garbage Collection is whenever the runtime takes a time to manage the allocation and release of memory for the application. In this case that is what's taking place.
垃圾收集是运行时管理应用程序内存分配和释放的时间。在这种情况下。
Please take a look at this filter that can be used with doTrace (I have version 6) so that you can analyze garbage collection and determine when it might be blocking your execution. https://www.jetbrains.com/profiler/help/CLR_Activity.html
请查看这个可与doTrace一起使用的过滤器(我有版本6),以便您可以分析垃圾收集,并确定它何时阻塞了您的执行。https://www.jetbrains.com/profiler/help/CLR_Activity.html
#1
2
If you want to find out what is causing GCs, what objects are being allocated and collected, you can do it via dotMemory. Here is a tutorial that explains how to optimize memory traffic: https://confluence.jetbrains.com/display/NETCOM/Tutorial+3+-+How+to+Optimize+Memory+Traffic+with+dotMemory
如果您想知道是什么导致GCs,什么对象被分配和收集,您可以通过dotMemory来完成。这里有一篇教程,解释如何优化内存流量:https://confluence.jetbrains.com/display/NETCOM/Tutorial+3+-+ how +to+ optimization +内存+流量+with+dotMemory
#2
1
A little late to the party but if you are using .Net then you are using managed code, which basically means that the .Net runtime disposes your objects accordingly so you don't have memory leaks as opposed to C or C++.
有点晚了,但是如果你在使用。net,那么你在使用托管代码,这基本上意味着。net运行时相应地处理你的对象,这样你就不会有内存泄漏,而不是C或c++。
Garbage Collection is whenever the runtime takes a time to manage the allocation and release of memory for the application. In this case that is what's taking place.
垃圾收集是运行时管理应用程序内存分配和释放的时间。在这种情况下。
Please take a look at this filter that can be used with doTrace (I have version 6) so that you can analyze garbage collection and determine when it might be blocking your execution. https://www.jetbrains.com/profiler/help/CLR_Activity.html
请查看这个可与doTrace一起使用的过滤器(我有版本6),以便您可以分析垃圾收集,并确定它何时阻塞了您的执行。https://www.jetbrains.com/profiler/help/CLR_Activity.html