CMIS-657: fixed memory leak

git-svn-id: https://svn.apache.org/repos/asf/chemistry/dotcmis/trunk@1482865 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/DotCMIS/binding/converter.cs b/DotCMIS/binding/converter.cs
index 9ba54f2..a9e6bef 100644
--- a/DotCMIS/binding/converter.cs
+++ b/DotCMIS/binding/converter.cs
@@ -35,6 +35,9 @@
     {

         private const string CMISNamespaceURI = "http://docs.oasis-open.org/ns/cmis/core/200908/";

 

+        private static object SerializerLock = new object();

+        private static Dictionary<string, XmlSerializer> SerializerDict = new Dictionary<string, XmlSerializer>(16);

+

         private delegate void ProcessAnyElement(XmlElement element);

 

         /// <summary>

@@ -104,13 +107,25 @@
         }

 

         /// <summary>

-        /// Deserializes an elemenet.

+        /// Deserializes a choice or defaultValue elemenet.

         /// </summary>

         private static T DeserializeElement<T>(XmlElement element)

         {

-            XmlRootAttribute xmlRoot = new XmlRootAttribute(element.LocalName);

-            xmlRoot.Namespace = CMISNamespaceURI;

-            XmlSerializer s = new XmlSerializer(typeof(T), xmlRoot);

+            Type type = typeof(T);

+            XmlSerializer s;

+

+            lock (SerializerLock)

+            {

+                if (!SerializerDict.TryGetValue(type.Name, out s))

+                {

+                    // the local name can either be "choice" or "defaultValue"

+                    XmlRootAttribute xmlRoot = new XmlRootAttribute(element.LocalName);

+                    xmlRoot.Namespace = CMISNamespaceURI;

+                    s = new XmlSerializer(type, xmlRoot);

+                    SerializerDict.Add(type.Name, s);

+                }

+            }

+

             return (T)s.Deserialize(new XmlNodeReader(element));

         }