I found memory leak in method:
// Nevron.Serialization.NSerializer
public object LoadFromStream(Type rootType, Stream stream, PersistencyFormat format, INSerializationFilter filter)
{
........
case PersistencyFormat.XML:
{
XmlSerializer xmlSerializer = new XmlSerializer(rootType, this.l11I1ll, this.l11IlII, null, null);
StreamReader textReader = new StreamReader(stream);
result = xmlSerializer.Deserialize(textReader);
break;
}
..............
}
(code decompiled using ILSpy)
Every time you create new instance of XmlSerializer , and every time XML serialization infrastructure dynamically generates new assemblies to serialize and deserialize specified types.
MSDN says:
To increase performance, the XML serialization infrastructure dynamically generates assemblies to serialize and deserialize specified types. The infrastructure finds and reuses those assemblies. This behavior occurs only when using the following constructors:
XmlSerializer. XmlSerializer(Type)
XmlSerializer. XmlSerializer(Type, String)
If you use any of the other constructors, multiple versions of the same assembly are generated and never unloaded, which results in a memory leak and poor performance. The easiest solution is to use one of the previously mentioned two constructors. Otherwise, you must cache the assemblies in a Hashtable, as shown in the following example.
You use another constructor to create XmlSerializer, and in this case you must reuse instance from hashtable.
This is possible to fix that or workaround?