Can anyone please tell me how I can free objects in C#? For example, I have an object:
Object obj1 = new Object();
//Some code using obj1
/*
Here I would like to free obj1,
after it is no longer required
and also more importantly
its scope is the full run time of the program.
*/
You don't have to. The runtime's garbage collector will come along and clean it up for you. That is why you are using C# and not unmanaged C++ in the first place :)
You do not. This is what a garbage collector does automatically - basically when the .NET runtime needs memory, it will go around and delete objects that are not longer in use.
What you have to do for this to work is to remove all liks to the object.
In your case....
obj1=null;
at the end, then the object is no longer referenced and can be claimed from the garbage collector.
Note that if the object has references to unmanaged ressources (like open files etc.) it should implement the Disposable patte (IDisposable interface) and you should explicitely release those references when you dont need the object anymore.
As others have mentioned you don't need to explicitly free them; however something that hasn't been mentioned is that whilst it is true the inbuilt garbage collector will free them for you, there is no guarantee of WHEN the garbage collector will free it.
All you know is that when it has fallen out of scope it CAN be cleaned up by the GC and at some stage will be.