Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: What is typical garbage collector overhead?

Tags:

c#

.net

clr

5% of execution time spent on GC? 10%? 25%?

Thanks.

like image 742
Vladimir Doloto Avatar asked Feb 15 '10 16:02

Vladimir Doloto


People also ask

What is garbage collector overhead?

Simply put, the JVM takes care of freeing up memory when objects are no longer being used. This process is called Garbage Collection (GC). The GC Overhead Limit Exceeded error is one from the java. lang. OutOfMemoryError family, and it's an indication of a resource (memory) exhaustion.

How does the .NET garbage collector work?

NET's garbage collector manages the allocation and release of memory for your application. Each time you create a new object, the common language runtime allocates memory for the object from the managed heap.

How many levels of generation does garbage collector use in net?

Garbage collection primarily occurs with the reclamation of short-lived objects. To optimize the performance of the garbage collector, the managed heap is divided into three generations, 0, 1, and 2, so it can handle long-lived and short-lived objects separately.

Why is garbage collection so high?

CPU usage will be high during a garbage collection. If a significant amount of process time is spent in a garbage collection, the number of collections is too frequent or the collection is lasting too long. An increased allocation rate of objects on the managed heap causes garbage collection to occur more frequently.


1 Answers

This blog post has an interesting investigation into this area.

The posters conclusion? That the overhead was negligible for his example.

So the GC heap is so fast that in a real program, even in tight loops, you can use closures and delegates without even giving it a second’s thought (or even a few nanosecond’s thought). As always, work on a clean, safe design, then profile to find out where the overhead is.

like image 98
ChrisF Avatar answered Oct 05 '22 13:10

ChrisF