导出合同时报错Exception of type 'System.OutOfMemoryException' was thrown
遇到一个问题,希望大神们帮帮忙@sp123
因为合同非标准化,所以只有一行一行的生成,但是一周左右就会出现较大的合同导不出的情况,问题出现后,一天左右后又能导出了,好像是系统释放了内存,报错时是执行到docWW.Save(dir);报错Exception of type 'System.OutOfMemoryException' was thrown,部分代码如下:
StringBuilder _HTML = new StringBuilder();
_HTML.Append("<html xmlns: v =\"urn:schemas-microsoft-com:vml\"");
_HTML.Append("xmlns:o =\"urn:schemas-microsoft-com:office:office\"");
_HTML.Append("xmlns:w =\"urn:schemas-microsoft-com:office:word\"");
_HTML.Append(" xmlns:m =\"http://schemas.microsoft.com/office/2004/12/omml\"");
_HTML.Append("xmlns =\"http://www.w3.org/TR/REC-html40\">");
_HTML.Append("<head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"><meta name=Generator content=\"Microsoft Word 15 (filtered)\">");
//_HTML.Append("<style> ");
//_HTML.Append(" .table-ww table{border-right:1px solid #F00;border-bottom:1px solid #F00}");
//_HTML.Append(" .table-ww table td{border-left:1px solid #F00;border-top:1px solid #F00}");
//_HTML.Append(" </style> ");
_HTML.Append("</head><body>");
。。。。。。。。。。。。。。(省略N个循环)
_HTML.Append("</body></html><br>");
#region 保存DOC文件
string dir = Server.MapPath("/template/MAC/" + fileName);
InitLog(dir.ToString() + "----DocumentBuilder START SAVE");
Document docWW = new Document();
DocumentBuilder builder = new DocumentBuilder(docWW);
//插入合同明细
builder.InsertHtml(_HTML.ToString());
//创建页脚
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Write(_footer);
docWW.Save(dir);
docWW = null;
GC.Collect();
InitLog(dir.ToString() + "----DocumentBuilder SAVE OK");
#endregion
_HTML.Clear();