In C# I know that my objects are garbage collected when they go out of scope and there are no more pointers/references to it. Is there a way to run some custom code when this garbage collection occurs?
Share
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.
Yes, it’s called a finalizer. http://msdn.microsoft.com/en-us/library/wxad3cah.aspx
Much of the C# documentation confusingly uses the term “destructor”. Although the C++ naming for a destructor is used in C# for a finalizer, the semantics are totally different. If you consistently use the word finalizer, there won’t be any confusion.