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

What are Action Filters in ASP.NET MVC and its use?

555


What is the difference between windows vista and .net framework 3.0 ?

539


In .net compact framework, can we free memory explicitly without waiting for garbage collector to free the memory?

543


what is split entity?

601


What is the significance of nonactionattribute?

579






i have done enough testing in life but now stated developing intereset in development work,Can i think of entering into development work that too in >Net after more then 4 years of testing experiece?

1746


Explain Model, view and Controllers in Asp.Net MVC?

558


what is entity data model?

586


What is work of clr?

571


Can you explain renderbody and renderpage in asp.net mvc?

550


What is entitytypes? : Entity framework

607


What is associationset? : Entity framework

560


Explain the tools used for unit testing in ASP.Net MVC

598


Explain the advantages and disadvantages of ASP.Net MVC over ASP.NET?

531


Does .NET Framework support SAX?

558