You must Sign In to post a response.
  • Category: XML

    Out of Memory Exception : XMl doc


    Are you looking for way resolve error Out of Memory Exception ? then read this thread to know more about it



    I have a windows service running 24*7.This service load xml messages from a queue and load to database.
    I have one worker thread which continuw to load messages.
    I am using XDocument.Parse(xmlmessages)methid to parse the xml message.
    then i call other method to serialize and deserialize the parsed xml message.
    Once the messages is loaded to database i free the resources of XDocument object

    XDocument=null..but sometime after running 30 hrs or 24 hrs i get Out of Memory Exception. please advice what i can do to free the memory resources.
  • #729460
    Hi,

    Check the below links

    http://social.msdn.microsoft.com/Forums/en-US/44d8f867-4784-4fb6-93b8-fd28cb0008af/outerxml-throwing-out-of-memory-exception

    http://stackoverflow.com/questions/3127699/why-would-an-out-of-memory-exception-be-thrown-if-memory-is-available

  • #729463
    There exist several reasons behind 'Out of Memory Exception'
    Some of them are
    - Low hardware resources
    - Database interaction without 'named pipe enable'
    - Resources are not properly closed like datareader, stream reader, stream writer, XML reader etc.
    Have you used xml reader to read your xml ? if yes then try to close it once work has finished with it.
    try to use Dispose in your class/program it will really useful to free up memory.
    i have write an article over it, you can check it below
    http://www.dotnetspider.com/resources/43616-Cleanup-unmanaged-objects.aspx

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #731340
    Hi Prasad,
    the main class file main.cs
    this class file contains one method

    var xmlMessage= XDocument.Parse(strMessage);
    var xData= GetXData.GetXML(xmlMessage);

    then i free up the resource from xData like below

    xData=null;

    the other class file GetXData.cs
    here i have the method..and in this class i get the out of memory exception.

    public static GetXML GetXML(XDocument xml)
    {
    XmlSerializer serializer;
    try
    {
    using (var reader = xml.CreateReader())
    {
    serializer = new XmlSerializer(typeof(XMLElementMessage), new XmlRootAttribute("Trade"));
    return serializer.Deserialize(reader) as XMLElementMessage;
    }
    }
    catch (Exception exp)
    {
    throw exp;
    }
    finally
    {
    serializer = null;
    }
    }

    the XMLElementMessage.cs file have all the element of xml message defiled like this

    [Serializable]
    public class XMLElementMessage
    {
    public string Name { get; set; }
    public string ID{ get; set; }
    public string Dept{ get; set; }
    public string Curr{ get; set; }
    }

    please let me know if you see any thing here where i should take care of memory issue?


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.