问题描述:我们在使用Aspose输出保存word文件和PDF文件时,内存会持续增高,并且释放不掉。我们分别使用了Java和.Net两个版本的Aspose,内存问题都存在。
项目场景:输出html内容到word文件或PDF文件,html内容包括文本、表格、图片、svg等内容,内容会比较大,也会有多次输出的情况。项目程序是以服务的形式持续运行,有输出任务传过来就调用输出方法。
Aspose版本:Java(18.8),.Net(18.8)
代码示例(Java):
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(“”);
doc.save(“……/test.docx”);// doc.save(“……/test.pdf”)
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(“”);
Saveoptions saveoption = SaveOptions.createSaveOptions(SaveFormat.DOCX);
//Saveoptions saveoption = SaveOptions.createSaveOptions(SaveFormat.PDF);
saveoption.setMemoryOptimization(true);
doc.save(“……/test.docx”,saveoption);// doc.save(“……/test.pdf”,saveoption)