I am writing a Windows application that needs to serialize and deserialize XML documents multiple times during its execution. Since I need to serialize and deserialize common types that are not known at compile time (I don't know a priori how many types I need for serialization / deserialization). I would like to know if it is good to store the cache of DataContractSerializer objects. I am creating an instance to serialize and deserialize objects.
I ask this question because I know that it is recommended to cache instances of the XmlSerializer class, because they create a dynamic assembly in memory under the hood, and assemblies dynamically created in memory do not collect garbage.
I read that the DataContractSerializer is based on generating lightweight code, but I'm not used to its details. That's why I ask this question, I need to understand, if I create DataContractSerializer instances as necessary, will this lead to a memory leak, since there will be an XmlSerializer?
I decided to use a DataContractSerializer instead of an XmlSerializer to serialize internal properties.
caching xml-serialization windows-services datacontractserializer
Carlos Loth
source share