Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How does Garbage collector(GC) works in .net

Answers were Sorted based on User's Feedback



How does Garbage collector(GC) works in .net..

Answer / aravindha raj

How, then, does the garbage collector achieve its magic? The
basic idea is pretty simple: it examines how objects are
laid out in memory and identifies all those objects that can
be ‘reached’ by the running program by following some series
of references.
When a garbage collection starts, it looks at a set of
references called the ‘GC roots’. These are memory locations
that are designated to be always reachable for some reason,
and which contain references to objects created by the
program. It marks these objects as ‘live’ and then looks at
any objects that they reference; it marks these as being
‘live’ too. It continues in this manner, iterating through
all of the objects it knows are ‘live’. It marks anything
that they reference as also being used until it can find no
further objects.
An object is identified, by the Garbage Collector, as
referencing another object if it, or one of its
superclasses, has a field that contains the other object.
Once all of these live objects are known, any remaining
objects can be discarded and the space re-used for new
objects. .NET compacts memory so that there are no gaps
(effectively squashing the discarded objects out of
existence) - this means that free memory is always located
at the end of a heap and makes allocating new objects very fast.
GC roots are not objects in themselves but are instead
references to objects. Any object referenced by a GC root
will automatically survive the next garbage collection.
There are four main kinds of root in .NET:
A local variable in a method that is currently running is
considered to be a GC root. The objects referenced by these
variables can always be accessed immediately by the method
they are declared in, and so they must be kept around. The
lifetime of these roots can depend on the way the program
was built. In debug builds, a local variable lasts for as
long as the method is on the stack. In release builds, the
JIT is able to look at the program structure to work out the
last point within the execution that a variable can be used
by the method and will discard it when it is no longer
required. This strategy isn’t always used and can be turned
off, for example, by running the program in a debugger.
Static variables are also always considered GC roots. The
objects they reference can be accessed at any time by the
class that declared them (or the rest of the program if they
are public), so .NET will always keep them around. Variables
declared as ‘thread static’ will only last for as long as
that thread is running.
If a managed object is passed to an unmanaged COM+ library
through interop, then it will also become a GC root with a
reference count. This is because COM+ doesn’t do garbage
collection: It uses, instead, a reference counting system;
once the COM+ library finishes with the object by setting
the reference count to 0 it ceases to be a GC root and can
be collected again.
If an object has a finalizer, it is not immediately removed
when the garbage collector decides it is no longer ‘live’.
Instead, it becomes a special kind of root until .NET has
called the finalizer method. This means that these objects
usually require more than one garbage collection to be
removed from memory, as they will survive the first time
they are found to be unused.

Is This Answer Correct ?    0 Yes 0 No

How does Garbage collector(GC) works in .net..

Answer / dilip tiwari

Basically Memory is divided into three part.Generation one,
Generation two and Generation three. Generation one is
small,Generation two is midium and generation three is
large in size, When we create any object by using new
keyword system will first calculate the bits require by the
object then check the bits avialble in memory (Generation
one) if bits found then allocate and point that using
Nextptrobj pointer. If there is no bits present then GC
come into picture. When GC run first it will check of
reference object know as GCRoot. These are by default
always reachable it mark these as live object. Then check
for objects pointed by these object it mark them also live
objects. It continue in this manner iterating through all
live object. As process finish all objects mark as live and
remaning objects are discarded from the memory and used by
the other objects.

Is This Answer Correct ?    0 Yes 0 No

How does Garbage collector(GC) works in .net..

Answer / rockpop5

nice info...

here are some more ques

http://www.iminfo.in/post/advanced-inteview-questions-dot-net-garbage-collection-part-one

Is This Answer Correct ?    0 Yes 0 No

How does Garbage collector(GC) works in .net..

Answer / nishith tripathi

Garbage Collector is a allocation deallocation memory for
an application

Is This Answer Correct ?    7 Yes 15 No

Post New Answer

More ASP.NET Interview Questions

Can we override the enablepartialrendering property of the scriptmanager class?

0 Answers  


Let's say I have an existing application written using vb6 and this application utilizes windows 2000 com+ transaction services. How would you approach migrating this application to.net?

0 Answers  


Hi please tell me what is ISNOTPOSTBACK,POSTBACK,AUTOPOSTBACK and also the extensions of aspx,asmx,ascx its urgent plz reply me soon....

6 Answers   Logica CMG,


2. Why did you choose this career?

2 Answers   Schwartz Oil, Swatz Oils,


Differentiate between client-side and server-side validations in web pages.

0 Answers  


What?s a bubbled event?

1 Answers  


What is owin authentication?

0 Answers  


What are the differences between clr & cts?

0 Answers  


How do http sessions work?

0 Answers  


what is structured data format?

2 Answers  


How to migrate from sqlserver 2005 to sql server 2000 (every one know reverse process of that )

2 Answers   Cap Gemini,


How do you handle session management in ASP.NET and how do you implement them. How do you handle in case of SQLServer mode ?

0 Answers   Microsoft,


Categories