Post your own serialized code:
Public classXmlutil {/// <summary> ///XML & DataContract Serialize & Deserialize Helper/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "Serialobject" ></param> /// <returns></returns> Public Static stringSerializer<t> (T serialobject)whereT:class { stringresult =string. Empty; using(MemoryStream mem =NewMemoryStream ()) { using(XmlTextWriter writer =NewXmlTextWriter (Mem, Encoding.UTF8)) {System.Xml.Serialization.XmlSerializer Ser=NewSystem.Xml.Serialization.XmlSerializer (typeof(T)); Ser. Serialize (writer, serialobject); Result=Encoding.UTF8.GetString (Mem. ToArray ()); } } returnresult; } Public StaticT deserialize<t> (stringStrwhereT:class{T result=NULL; using(MemoryStream MemoryStream =NewMemoryStream (Encoding.UTF8.GetBytes (str))) { using(StreamReader StreamReader =NewStreamReader (MemoryStream)) {System.Xml.Serialization.XmlSerializer XmlSerializer=NewSystem.Xml.Serialization.XmlSerializer (typeof(T)); Result=(T) xmlserializer.deserialize (MemoryStream); } } returnresult; } }
The above-written continuous serialization will not have memory overflow performance issues, has been told to directly refer to the company of an old bird packaged dll to serialize, and later found that there is always a memory overflow, paste its wrong wording, only for the lesson:
Public classXmlutil {/// <summary> ///XML & DataContract Serialize & Deserialize Helper/// </summary> /// <typeparam name= "T" ></typeparam> /// <param name= "Serialobject" ></param> /// <returns></returns> Public Static stringSerializer<t> (T serialobject)whereT:class { //Try//{XmlSerializer ser =NewXmlSerializer (typeof(T)); System.IO.MemoryStream Mem=NewMemoryStream (); XmlTextWriter writer=NewXmlTextWriter (Mem, Encoding.UTF8); Ser. Serialize (writer, serialobject); Writer. Close (); returnEncoding.UTF8.GetString (Mem. ToArray ()); //} //catch (Exception ex)//{ //return null; //} } Public StaticT deserialize<t> (stringStrwhereT:class { //Try//{XmlSerializer Myserializer =NewXmlSerializer (typeof(T)); StreamReader mem2=NewStreamReader (NewMemoryStream (System.Text.Encoding.UTF8.GetBytes (str)), System.Text.Encoding.UTF8); return(T) myserializer.deserialize (MEM2); //} //catch (Exception)//{ //return null; //} } //Public static string Json_serializeobject (object value)//{ //return Newtonsoft.Json.JsonConvert.SerializeObject (value); //} //Public Static Object Json_deserializeobject (string value)//{ //return Newtonsoft.Json.JsonConvert.DeserializeObject (value); //} //Public static T json_deserializeobject<t> (string value)//{ //return newtonsoft.json.jsonconvert.deserializeobject<t> (value); //}}
Ah, the veteran of the time to write code is so casual? See the tried catch that was commented out I guess he used to think there was something wrong here, but he didn't find it. Directly put in memory, flow is not released Ah ...
Summary of C # serialization