A Doubt regarding Garbage Collection Process in .net.

Posted by Anishabathija under C# on 5/6/2013 | Points: 10 | Views : 1095 | Status : [Member] | Replies : 1
Which of the following is true about .net garbage collection process ?

1)Finalize method should be implemented for all the classes , irrespective of the class uses any managed or unmanaged resources.

2)Finalize method should always be accompanied by IDisposable.Dispose method

3)Dispose method should prevent the Finalize method from running the GC.Suppress Method .

4)If IDisposable.Dispose method is implemented , there is no need to implement Finalize method.


Posted by: Raj.Trivedi on: 5/6/2013 [Member] [MVP] Starter | Points: 25

Hello Anishabathija

Garbage collection is a very good utility to destroy resources if they are not required.

Answer 1 : - finalize method is only neccessary to use to the whose classes whose objects are created example

if i have a class called Customer.cs

and in the page i create a an object of Customer class such as objcustomer then i would rather use try - catch block and in finally i will write this code.

Customer objcustomer = new Customer()
catch(exception ex)

if(objcustomer !=null)
objscutomer = ""; this will release the memory.

Answer 2 : - http://msdn.microsoft.com/en-us/library/system.idisposable.dispose.aspx

Answer 3 :- http://msdn.microsoft.com/en-IN/library/system.gc.suppressfinalize.aspx

Answer 4 :- Refer to link in answer 2

"Sharing is Caring"
Please mark as answer if your Query is resolved

Anishabathija, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response