We're sorry Aspose doesn't work properply without JavaScript enabled.

# Free Support Forum - aspose.com

Hi Aspose,
When I loaded and saved big word doc http://www.fileshare.ro/e3172439276 using Aspose.Words_17.2.0. It can be opened with microsoft office. I’m aware that this word doc is big and contains a large amount of picture. The loading file takes 800MB of RAM and it threw exception when saving file.
My sample code:

try
{
Aspose.Words.Document doc = new Aspose.Words.Document(inputDocFile);
doc.Save(outputDocFile);
}
catch (Exception e)
{}


Thanks you.

Hi there,

Thanks for your inquiry. We introduced an option (SaveOptions.MemoryOptimization) to optimize memory consumption during these scenarios. When its value is set to true it will improve document memory footprint but will add extra time to processing. This optimization is only applied during save operation. Please try this property. Hope this helps you.

If you still face problem, please share your output file format. We will investigate the issue and provide you more information on this.

Thanks for your reply. I tested option MemoryOptimization and “out of memory” exception does not appear. Sample file is mentionted in the previous comment
There 2 other issues.
- 1st issue: Process’s memory is very high (1034MB) and does not drop when i exited the function ConvertTo(). More specifically,
+ 1st ConvertTo: Process’s memory is 1034 MB
+ 2nd ConvertTo: Process’s memory is 1485 MB
+ 3rd ConvertTo: Process’s memory is 1734 MB
+ 4nd ConvertTo: Process’s memory is 734 MB
My question is: Is there a way to release memory manually when ConvertTo finishes instead of GarbageCollector?
- 2nd issue: doc --> pdf tooks more than 1 hours and still not finishes
My question is: Does it has timeout option ?

static void Main(string[] args)
{
string strInFile = "F:\big.doc";
string strOutFile = "F:\outfile.doc";
for (int i = 0; i < 10; i++)
{
ConvertTo(strInFile, strOutFile, "doc");
}
}
static bool ConvertTo(string strInFile, string strOutFile, string strType)
{
try
{
Aspose.Words.Document doc = new Aspose.Words.Document(strInFile);
if (strType == "doc")
{
WordML2003SaveOptions option = new WordML2003SaveOptions();
option.MemoryOptimization = true;
doc.Save(strOutFile + ".doc", option);
}
else if (strType == "pdf")
{
Aspose.Words.Saving.PdfSaveOptions option = new Aspose.Words.Saving.PdfSaveOptions();
option.MemoryOptimization = true;
doc.Save(strOutFile + ".pdf", option);
}
}
catch
{
return false;
}
return true;
}


Hi there,

Thanks for your inquiry. Please note that performance and memory usage all depend on complexity and size of the documents you are generating. While rendering a document to fixed page formats (e.g. PDF), Aspose.Words needs to build two model in the memory – one for document and the other for rendered document.

In terms of memory, Aspose.Words does not have any limitations. If you’re loading huge Word documents into Aspose.Words’ DOM, more memory would be required. This is because during processing, the document needs to be held wholly in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

We’re always working on improving performance; but, rendering will be always running slower than simple saving to flow formats (e.g. doc/docx).

 truongminhlong:

My question is: Is there a way to release memory manually when ConvertTo finishes instead of GarbageCollector?

- 2nd issue: doc --> pdf tooks more than 1 hours and still not finishes

When the document is closed, all the DOM data is purged from memory during the next garbage collector cycle.

 truongminhlong:

- 2nd issue: doc --> pdf tooks more than 1 hours and still not finishes

My question is: Does it has timeout option ?

Thread.Abort method is unsafe way for interrupt Aspose.Words execution. Aspose.Words has special interruption way using class InterruptionToken. Please use following code examples to achieve your requirement.

Hope this helps you. Please let us know if you have any more queries.

///
/// My Aspose document.
///
public class MyDocument : Aspose.Words.Document
{
public MyDocument(string fileName) : base(fileName) { }

public bool TryToSave(string fileName, int timeout)
{
InterruptionToken token = new InterruptionToken();
bool finished = SaveWithTimeout(token,
() =>
{
try
{
Save(fileName);
}
catch (Exception ex)
{
Console.WriteLine("Interrupted");
}
}, timeout);
return finished;
}

{
if (!finished)
{
token.Interrupt();
}
return finished;
}
}

MyDocument myDoc = new MyDocument(MyDir + "in.docx");
bool done = myDoc.TryToSave(MyDir + "Out.pdf", 1000);
Console.WriteLine(done? "Converted" : "Interrupted by timeout.");