I have the code below. Since the method is static
and XmlSerializer
does not implement Dispose
, every method call, the system heaps in memory or GC
garbage collector ) can clear this variable ?
And in the case of classes that do not have Dispose
, to destroy the variable can I do converter = null
, or do I have to do something else? For my understanding, null
, only clears the value, but leaves the variable in the application pointer.
public static string ConverterObjetoEmTexto(object dados)
{
var retorno = "";
XmlSerializer converter = new XmlSerializer(dados.GetType());
using (StringWriter textWriter = new StringWriter())
{
converter.Serialize(textWriter, dados);
retorno = textWriter.ToString().Replace("encoding=\"utf-16\"", "encoding=\"utf-8\"");
return retorno;
}
}