How does Garbage collector(GC) works in .net
Answer Posted / viresh rajput
The Garbage Collector (GC) can be considered the heart of
the .NET Framework. It manages the allocation and release of
memory for any .NET application. In order to create good
.NET applications, we must know how the Garbage Collector
(GC) works.
All the living objects from the managed heap are divided in
three groups by their age. Those groups are generically
called "Generations". Those generations are very useful to
prevent memory fragmentation on the managed heap. The
Garbage Collector (GC) can search for dead object on each
generation at a time (partial collections), to improve the
collecting performance.
Now let’s see what the Garbage Collector (GC) is using each
generation for:
Generation 0 (Gen0) contains all the newly created
objects and it is located on the top of the heap zone
(higher memory addresses). All the objects contained by Gen0
are considered short-lived object and the Garbage Collector
(GC) is expecting to them to be quickly destroyed in order
to release the used memory space. Due to this presumption,
the Garbage Collector (GC) will try to collect dead objects
most often from Gen0 because it is cheapest.
Generation 1 (Gen1) contains all the living objects from
Gen0 that have survived to several Gen0 collects. So those
objects are upgraded from Generation 0 to Generation 1. Gen1
is defined in the middle of the heap zone and it is exposed
to fewer garbage collects than Gen0. Gen1’s collects are
more expensive than the Gen0’s so the Garbage Collector (GC)
will try to avoid them if it is not really necessary.
Generation 2 (Gen2) contains all the living objects from
Gen1 that have survived to several Gen2 collects. Those
objects are considered long-lived objects and destroying
them is very expensive. Because of this, the Garbage
Collector (GC) will hardly try to collect them. The Gen2
zone is located on the bottom of the managed heap zone
(lowest memory addresses).
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
Define repository pattern in asp.net mvc? : asp.net mvc
Describe in brief .net framework and its components.
Where sessions are stored in asp.net?
What is difference between mvc and asp.net? : Asp.Net MVC
What is query string? What are its advantages and limitations?
Where is the session stored?
What is application variable?
Which is faster viewbag or viewdata?
What are the main requirements for caching?
what are the ihttphandler and ihttphandlerfactory interfaces ?
Why session is necessary in web application?
What does asp stand for in asp.net?
What are the advantages of using sql stored procedures instead of adhoc sql queries in an asp.net web application?
How can you handle errors in Web API?
Error : The operation couldn’t be performed because ole db provider sqlncli10 for linked server was unable to begin a distributed transaction.00000110 oledb provider for linked server returned message the partner transaction manager has disabled its support for remote/network transactions. I can able to execute the stored procedure in sql server but when i run the web page getting error like above. I did all the configuration. what is the solution?