From time to time, our web application will cause this error:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
The application is C# ASP.NET 4.5 Web Forms application, running on Windows 2008 R2 server with 6G memory. We have increased memory several times, but it still happens. So I am wondering if its application's problem? What could be the reason?
edit
I have this stack, don't know if it helps at all:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
Generated: Wed, 29 Jul 2015 08:49:24 GMT
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at ASP.popups_downloadtrendpdf_aspx.__BuildControlTree(popups_downloadtrendpdf_aspx __ctrl)
   at ASP.popups_downloadtrendpdf_aspx.FrameworkInitialize()
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.popups_downloadtrendpdf_aspx.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
edit
So this is the code that generates PDF, its based on XSL-FO string. Does this caused problem?
PDFGenerator.PDFGenerator svc = new PDFGenerator.PDFGenerator();
byte[] myfile = svc.ProcessFO(foString);
if (myfile != null)
{
    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.Clear();
    response.AddHeader("Content-Type", "application/pdf");
    response.AddHeader("Content-Disposition", "attachment; filename=" + filename + "; size=" + myfile.Length.ToString());
    response.Flush();
    response.BinaryWrite(myfile);
    response.Flush();                    
 }
edit
code for ProcessFO():
    [WebMethod]
    public byte[] ProcessFO(string requestFO)
    {
        byte[] result = null;
        FODocument doc = new FODocument();
        try
        {
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(requestFO);
            using (MemoryStream stream = new MemoryStream(byteArray))
            {
                using (MemoryStream pdfStream = new MemoryStream())
                {
                    doc.generate(stream, pdfStream);
                    result = pdfStream.ToArray();
                }
            }
        }
        catch (System.Exception exc)
        {
            logger.Debug("Trouble in ProcessFO: " + exc.Message);
            logger.Debug(exc.StackTrace);
        }
        return result;
    }
 
     
    