Monday, 16 July 2012

Garbage Collector - "Kachra" - Man

Garbage Collector : "If you have time to lean, you have time to clean"

1. This is the process that runs when we run our application. This is a DAEMON Thread.
     More : Garbage Collector is one of the two processes that runs by default when you run an  applicaiton. Second is the Main program(Duh !!)

2. Garbage collector is only called when the application request memory and there is not enough memory.(Myth : It is always called.

3. "Mark and Sweep" : This is a method comprises of the following.
  • GC assumes everything on the memory is a trash.
  • Prepares a graph of all the memory that is currently referenced by the application.
  • Compacts the heap by moving the memory in use to the start of the Heap.
  • The new heap is formed and the vacant is left and freed.      
4. GC is only effective if performed on smaller memory objects. It will obviously have an adverse effect if the GC tries to move let say 30000 byte of memory.

5. To perform a programmer specific Garbage collection GC.Collect() is used. To use this we have to suppress the finalize method. Because if not suppresed, Garbage collector will work twice and performance will be surely adverse.

6. AAO TWIST KAREY : Dont think that GC.Collect() is called and it will destroy the object and will free up the memory. GC.Collect() has a proven high "Programmer Headache" rate. Please do not use it. Let .NET do all the garbage collection.

No comments:

Post a Comment