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 application. 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.)
- 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.
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. 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.

Comments
Post a Comment