Let’s say I have a class:
class Class1
{
public List<Class2> Classes;
}
that I deserialize with XmlSerializer and Class2 creates some stuff that I should Dispose. Should I dispose everything myself or is that going to be done automatically?
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.
Rule of thumb: if you’re using a class that implements IDisposable, you should make sure to call the Dispose() method (you can use a using block for this). If the class doesn’t implement IDisposable than .NET will take care of it for you.
For your own classes, you should implement IDisposable if your class has a member variable that either implements IDisposable or is unmanaged.