I have this method:
public static string XmlSerialize<T>(T data)
{
string result;
using (StringWriter stringWriter = new StringWriter())
{
XmlWriterSettings settings = new XmlWriterSettings
{
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
};
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] { typeof(T) })[0];
serializer.Serialize(writer, data, ns);
}
result = stringWriter.ToString();
}
return result;
}
This is simple method to serialize object into xml. But this method have memory leak, and I haven't idea where is it.
Can anyone help me find it?