System Out of Memory Exception while saving word doc

Aspose version : 15.11.0.0

I am trying to create and save a word document with approx 15000 pages, with each page coming to around 35kb. I am able to create the file, but I keep running into out of memory exception when trying to save the file. I could save the file only if there aren’t more than 3000 pages.

I’m freeing up used memory by running the garbage collector after creating every page.
I’m also deleting the temp files created once 2 docs have been merged into a single doc. Each doc approximately has 1000 pages.

Are there any other ways that I can do to get rid of this error?

@ranadeeprddy

Thanks for your inquiry. Please use SaveOptions.MemoryOptimization property as shown below to optimize the memory. Hope this helps you.

Document doc = new Document(MyDir + "in.doc");

// When set to true it will improve document memory footprint but will add extra time to processing. 
// This optimization is only applied during save operation.
DocSaveOptions saveOptions = new DocSaveOptions();
saveOptions.MemoryOptimization = true;

doc.Save(MyDir + @"MemoryOptimization Out.doc", saveOptions);