Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GC generation 3 appearing in windbg

Tags:

c#

.net

clr

I've a dump file of a process I'm running (trying to find a memory leak)

One thing I've noticed is that when I dump the bigger objects via !do windbg tells me that they are GC generation 3 ??

All of these are byte arrays so when I look at all the byte arrays in the dump I can see GC generations 0, 1, 2 & 3.

Could someone explain whats going on here as I thought there was only 3 generations of GC.

> 0:000> !do 0x0000000011b47450 
Name: System.Byte[]
MethodTable: 000007fef7d2e798
EEClass: 000007fef7932670
Size: 131096(0x20018) bytes
GC Generation: 3
Array: Rank 1, Number of elements 131072, Type Byte
Element Type: System.Byte
Fields:
None
like image 899
Johnv2020 Avatar asked Nov 30 '11 17:11

Johnv2020


People also ask

Does C# have garbage collection?

The C# garbage collection uses three generations in total: Generation 0—This generation holds short-lived objects. Here's where the collection process happens most often.

What is garbage collector in C#?

The garbage collector (GC) manages the allocation and release of memory. The garbage collector serves as an automatic memory manager. You do not need to know how to allocate and release memory or manage the lifetime of the objects that use that memory.

How does C# handle garbage collection?

Garbage collection handles memory allocation safely so that no objects use the contents of another object mistakenly. The constructors of newly created objects do not have to initialize all the data fields as garbage collection clears the memory of objects that were previously released.

What is large object heap in C#?

If an object is greater than or equal to 85,000 bytes in size, it's considered a large object. This number was determined by performance tuning. When an object allocation request is for 85,000 or more bytes, the runtime allocates it on the large object heap.


1 Answers

The .NET Framework has a fourth heap ("generation") specifically for large objects, called -- appropriately enough -- the Large Object Heap. Objects larger than 85,000 bytes are allocated onto that heap.

For reference: http://msdn.microsoft.com/en-us/magazine/cc163833.aspx

One undocumented feature of the "!dh" command is that you can easily look at the large object heap as well. In looking at a lot of output, I noticed some values listed as coming from Generation 3. Because the .NET garbage collector, at least according to everything I read, only has the three generations (0, 1, and 2), I was a little confused. Thinking it may be the large object heap, I manually dumped the large object heap and compared values. Sure enough, that's what I saw. To see the objects in the large object heap, use 3 as the generation like this: "!dh –stat –gen 3".

like image 94
Cole Campbell Avatar answered Oct 06 '22 01:10

Cole Campbell