How Garbage Collector identifies the objects which are not
in use?

Answer Posted / kiran vaidya

When any new object is created, it has two references
assigned, one is present on the application's stack area
and other is on the GC's stack. With creation of any new
object, it will be automatically assigned the generation as
0.
Now, there are two cases where object's reference is
removed from application stack.

1.When programmer assignes any object as 'null', the
reference on the application's stack to the specific object
is automatically removed.

2.When the function scope is ended, the references to those
objects in the function are automatically removed from
stack.
Now, GC compares the entries of references at its own
stack Vs the entries of references available at the
application stack.
By comparing them, it finds the object's references in
its stack to which, no match was found in the application
stack and releases memory allocated to them.

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it possible to share a view across multiple controllers?

729


If I have multiple filters implemented, what is the order in which these filters get executed?

706


What are the versions of .net framework?

734


What is difference between viewbag and viewdata and tempdata?

739


What is managed extensibility framework?

730






What are the options can be configured in AJAX helpers?

762


Can I uninstall microsoft .net framework?

737


how can you enhance the performance of entity framework?

780


how do you query in entity model when the result has a join from from different database other than the entity model?

734


What is connected scenario? : Entity framework

721


What is net framework 3.0 ?

783


What are the possible razor view extensions?

759


What are the new features 3.5 framework against with the tool?

744


What you mean by routing in asp.net mvc?

725


What are the new enhancements done in default project template of asp.net mvc 4?

772