I have piece of code that the Ants profiler points to that is causing a memory leak. I have monitored the application over a period of 1 week, but the memory seems to be increasing and not coming back. SO I'm a bit concerned with the below code.
public void printXML(XmlDocument doc)
{
//System.Threading.Timer timer = null;
XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true };
new System.Threading.Timer((_) =>
{
using (var writer = XmlWriter.Create(_folderDestination, settings))
{
// Task.Delay(15000).ContinueWith(_ => doc.Save(writer));
doc.Save(writer);
}
}).Change(15000, -1);
}
Everytime the method printXML
is called it would write the doc
to the _folderDestination
after a period of 15secs. This is what I want to achieve. But the above code seems to be leaking memory and the memory never returns back. So if someone could help to optimize it, it would be great.