Garbage Collection Notifications in .NET 4.0

0 comments
Memory management is primary for any application. From the very beginning, we have used destructors,  or deleted the allocated memory whilst using the other programming languages like C or C++.  C# on the other hand being a proprietor of .NET framework provides us a new feature so that the programmer does  not have to bother about the memory deallocation and the framework does it automatically.

The basic usage is :
  1. Always leave local variable.
  2. Set class variables, events etc to null. 

This leaves us with lots of queries. When does the garbage collection executes? How does it affect the current application? Can I invoke Garbage collection when my system / application is idle ?

These questions might come to any developer who has just came to .NET environment. We were doing the application just blindly taking it account that this might be the basic usage of .NET applications, and there might be a hidden hand for us who works for us in background. There is an alternative to call the Garbage collection using
GC.Collect()

But according to the documentation, GC.Collect() is a request.It is not guaranteed that the Collection process will start after calling the method and the memory is reclaim So, there is still uncertainty whether actually the Garbage Collection will occur or not.

READ MORE >>
http://www.abhisheksur.com/2010/08/garbage-collection-notifications-in-net.html

0 comments: