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).
Garbage collection is the memory management process for objects in the heap. As objects are allocated to the heap, they run through a few collection phases – usually rather quickly as the majority of objects in the heap have short lifespans.
Java Memory Management, with its built-in garbage collection, is one of the language's finest achievements. It allows developers to create new objects without worrying explicitly about memory allocation and deallocation, because the garbage collector automatically reclaims memory for reuse.
Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java. A GC-enabled programming language includes one or more garbage collectors (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program.
An application that spends 1% of its execution time on garbage collection will loose more than 20% throughput on a 32-processor system. If we increase the GC time to 2%, the overall throughput will drop by another 20%. Such is the impact of suspending 32 executing threads simultaneously!
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With