Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Garbage Collection

2 views
Skip to first unread message

Scott M.

unread,
Aug 2, 2009, 1:52:45 PM8/2/09
to
Does the GC collect immediately when an applicaiton starts?

If I put the following as the very first line of code in my application, I
get a result of 1.

Console.WriteLine("Gen 0 has been swept {0} times.", GC.CollectionCount(0))

-Scott


Muhammed Fawzy

unread,
Aug 3, 2009, 4:54:34 PM8/3/09
to
GC kicks in when the tuning logic decides. This happen when you have enough
garbage.
Gen 0 collections happen more frequently than Gen 1, and Gen 2 collections,
usually Gen 0 collection takes less than 1-2 ms.
When the application starts, there are some allocations done by the .Net
Framework itself this is even before the first line of your code executes,
for example, static constructors for types you reference.
The fact there are some code that excuses before your main gives the
possibility that code is doing some allocation. Since what triggers a GC
is allocation, then it is absolutely normal to see a couple of Gen 0 GCs in
the startup path.

Is this causing you any perf issues?
Thanks
Muhammed
CLR Performance Team.

"Scott M." <s-...@nospam.nospam> wrote in message
news:#YUbpn5E...@TK2MSFTNGP03.phx.gbl...

Scott M.

unread,
Aug 3, 2009, 7:04:13 PM8/3/09
to
Thanks Muhammed. No, it's not causing any problems, I was just curious as
to why I'd see Gen 0's collected before my app. has a change to do anything.

-Scott

"Muhammed Fawzy" <mfaw...@hotmail.com> wrote in message
news:B007D6B2-6DB1-4DF3...@microsoft.com...

0 new messages