Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Garbage collection happen for Classes having static methods in C#/VB.NET?

Does setting the object to null make it MARKED for GC?

EDIT: A class has got multiple static methods. when using these methods in your program, what is the best way to ensure the objects are marked for GC after a certain point?

like image 968
RJ. Avatar asked Nov 30 '09 17:11

RJ.


1 Answers

Methods aren't garbage collected at all - so it's not really clear what your question means.

Likewise you never set an object to null. You can make the value of a variable null, but that doesn't nothing to any object that the variable previously referred to. It just means that next time the garbage collector looks for live object, that variable won't contribute any object to the set of objects which must be kept alive at the end of the GC.

I suggest you read Jeffrey Richter's article on garbage collection for a bit more background, then ask any further specific questions when you've got to grips with the basics.

like image 117
Jon Skeet Avatar answered Sep 29 '22 09:09

Jon Skeet