dotTrace Performance Profiler 所说的[垃圾收集]是什么意思?
这张图片中的 [垃圾收集] 是什么意思?还有“20个电话”的事吗?
我的意思是,我怎样才能弄清楚为什么 GC 花了这么长时间?是不是收集了很多小东西?一个大的?关于如何优化这个的任何提示吗?
有问题的代码是:
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
对象,但我认为收集一个单个大对象应该是即时的(而不是收集一堆小对象)对象)。
What does [Garbage collection] mean in this pic? And the "20 calls" thing?
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?
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想找出导致 GC 的原因、正在分配和收集哪些对象,可以通过 dotMemory 来完成。以下教程解释了如何优化内存流量:https://confluence.jetbrains.com/display/NETCOM/Tutorial+3+-+How+to+Optimize+Memory+Traffic+with+dotMemory
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
有点晚了,但如果您使用 .Net,那么您正在使用托管代码,这基本上意味着 .Net 运行时会相应地处理您的对象,因此与 C 或 C++ 不同,您不会出现内存泄漏。
垃圾收集是指运行时需要一些时间来管理应用程序的内存分配和释放。在这种情况下,这就是正在发生的事情。
请看一下这个可以与 doTrace 一起使用的过滤器(我有版本 6),以便您可以分析垃圾收集并确定它何时可能阻止您的执行。
https://www.jetbrains.com/profiler/help/CLR_Activity.html
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++.
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