.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
satyapriyanayak
SP
Sambanthamoorthy
Swati Kadam
rosgeppe

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

How Garbage Collector (GC) Works?

Posted By :Amit Mehra     Posted Date :September 07, 2008    Points :10   Category :.NET Framework 
The methods in this class influence when an object is garbage collected and when resources allocated by an object are released. Properties in this class provide information about the total amount of memory available in the system and the age category, or generation, of memory allocated to an object. Periodically, the garbage collector performs garbage collection to reclaim memory allocated to objects for which there are no valid references.

Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory. Alternatively, an application can force garbage collection using the Collect method.
Garbage collection consists of the following steps:

The garbage collector searches for managed objects that are referenced in managed code.

The garbage collector attempts to finalize objects that are not referenced.

The garbage collector frees objects that are not referenced and reclaims their memory.

You can also find related Interview Question to How Garbage Collector (GC) Works?  below: 

Can we force garbage collector to run?

  
System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arise. (More...)

In .NET Compact Framework, can I free memory explicitly without waiting for garbage collector to free the memory?

  
Yes you can clear the memory using gc.collect method but it is recommended that u should not call this becouse we don't know the exact time when the gc will be called automatic. (More...)

How can U Call garbage Collector method()?

  

GC.Methodname();

please follow this link for full lenghth details:

http://www.developer.com/net/csharp/article.php/3343191/C-Tip-Forcing-Garbage-Collection-in-NET.htm (More...)

How can I find out what the garbage collector is doing?

  
Lots of interesting statistics are exported from the .NET runtime via the '.NET CLR xxx' performance counters. Use Performance Monitor to view them. (More...)

What is GC (Garbage Collection) and how it works

  
One of the good features of the CLR is Garbage Collection, which runs in the background collecting unused object references, freeing us from having to ensure we always destroy them. In reality the time difference between you releasing the object instance and it being garbage collected is likely to be very small, since the GC is always running.
[The process of transitively tracing through all pointers to actively used objects in order to locate all objects that can be referenced, and then arranging to reuse any heap memory that was not found during this trace. The common language runtime garbage collector also compacts the memory that is in use to reduce the working space needed for the heap.]

Heap:
A portion of memory reserved for a program to use for the temporary storage of data structures whose existence or size cannot be determined until the program is running.
(More...)

Can we force garbage collector to run?

  
Yes,
System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arises. (More...)

What is Garbage collector ?

  
Garbage collection consists of the following steps:
? The garbage collector searches for managed objects that are referenced in managed code.
? The garbage collector attempts to finalize objects that are not referenced.
? The garbage collector frees objects that are not referenced and reclaims their memory.

Enforce garbage collection - System.GC.Collect();
(More...)

How can I find out what the garbage collector is doing?

  
Lots of interesting statistics are exported from the .NET runtime via the '.NET CLR xxx' performance counters. Use Performance Monitor to view them. (More...)

What do you mean by garbage collector in asp.net?

  
Garbage collection is a CLR feature which automatically manages memory.We forget to release the objects and while coding. CLR of .net framework automatically takes care of this.CLR runs on non-deterministic to see the unused objects and cleans them. One
side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. So, we should not put code into a class destructor
to release resources. (More...)

How can we force garbage collector to run ?

  
System.GC.Collect() forces garbage collector to run. (More...)

When Garbage Collector run?

  
Garbage Collector runs :
1. When the system has low physical memory
2. Acceptable memory heap is increased.
3. GC.Collect method is called. (More...)

What is Garbage Collector in .NET

  
The .NET garbage collector provides a high-speed allocation service with good use of memory and no long-term fragmentation problems.
Example

class X
{
// implicit dtor ~X()
// created for you automatically by C#
}

class Y
{
~Y() // explicit dtor, same as Finalize
{
// some code
}
}

//verbose syntax:

class Z
{
protected override void Finalize()
{
// code
// call to base.Finalize();
}
}
(More...)

What is JIT (just in time)? how it works?

  
Before Microsoft intermediate language (MSIL) can be executed, it must be converted by a .NET Framework just-in-time (JIT) compiler to native code, which is CPU-specific code that runs on the same computer architecture as the JIT compiler.
Rather than using time and memory to convert all the MSIL in a portable executable (PE) file to native code, it converts the MSIL as it is needed during execution and stores the resulting native code so that it is accessible for subsequent calls.
The runtime supplies another mode of compilation called install-time code generation. The install-time code generation mode converts MSIL to native code just as the regular JIT compiler does, but it converts larger units of code at a time, storing the resulting native code for use when the assembly is subsequently loaded and executed.
As part of compiling MSIL to native code, code must pass a verification process unless an administrator has established a security policy that allows code to bypass verification. Verification examines MSIL and metadata to find out whether the code can be determined to be type safe, which means that it is known to access only the memory locations it is authorized to access. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend