I just can’t find a simple answer to this simple question I have from Dr Google. I have the following serializing function which I put in a static module. It is called many times by my application to serialize lots of XML files. Will this cause memory to over grow? (Ignore the text write part of the code)
public static void SerializeToXML<T>(String inFilename,T t)
{
XmlSerializer serializer = new XmlSerializer(t.GetType());
string FullName = inFilename;
TextWriter textWriter = new StreamWriter(FullName);
serializer.Serialize(textWriter, t);
textWriter.Close();
textWriter.Dispose();
}
No. There will be no memory over growing.
staticwill let you callSerializeToXMLmethod without create a new instance of the class. Not anything else.So if you’re calling this method many times, You even shrinking the memory usage with a
staticmethod.Though you wrote to ignore the text write part, You should use using statement for unmanaged resources: