How can I call a GC in .net when I have done with the object that i created for a class.
If I sets an object value as Null
objClassObject=NULL;
Does it releases all the objects and resources associated with it. ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Setting an object to null will not cause the GC to swoop in and clean up memory. It helps to first understand what you are doing, and luckily, the GC is well documented:
Links to Various GC related topics.
The answer is that 99.999% of the time (made up number, yes) you don’t need to. If you have profiled and found that you actually do need to force a GC pass, you can use the GC class to attempt to do it. You really should know what you are doing though, and there is no guarantee that the GC will do exactly what you want.
Raymond Chen recently wrote a few good articles on this subject:
Everybody Thinks about the GC the Wrong Way
When Does an Object Become Eligible for Garbage Collection?
However, if you create a class that manages some native resource, you will then want to implement the IDisposable interface as the GC will not / cannot reclaim unmanaged resources.