Click here to Skip to main content
15,889,826 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:


I just want to know, if I have a small Application that stores a message in a string that comes from a Textbox and then displays it in a messageBox...

When does the Garbage Collector come in ?

I have to draw a Diagram and Explain the whole Scenario...
Can someone please Explain when it starts and how Exactly it works

Thanks in Advance :)

Posted
Updated 24-Nov-09 8:43am
v2

The simplest answer is that it will run when it needs to.  The GC checks the dependency between objects and structure in memory and detects when for nodes with no references.  When a threshold is met (e.g. a certain amount of memory has been consumed) it starts checking for dereferenced memory and starts calling finalizers and deallocating memory.  The level of memory at which this happens is related to the size of the processors L1 cache and a number of other factors.  There are different GCs for different types of application - which one is used depends upon the OS (desktop or server) and configuration.  They use different strategies for deciding how and when to deallocate memory.  This is a big subject that is relatively well covered on MSDN and plenty of other sources.  Try using Google and searching.

 
Share this answer
 

I Guess nobody like this Question... Lol!!

 
Share this answer
 

Garbage collection is a complex subject (I don't fully understand it) but the following simple answers should cover what you need to know for now.

The point at which the garbage collector actually runs cannot be determined. If there is pressure for memory then it will run when needed.

If you mean when are your objects eligible for collection - when there are no references remaining to them.

 
Share this answer
 

This is for an assignment ? Basically, the GC will run when the app closes.  Also, basically, 99.9% of people writing .NET code have no need to understand when the GC runs.

There are books that explain the cycles of the GC, if this is a school assignment, did they not give you such a book to read ?

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900