Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Jan 24, 2022 8:34 am

Hello,

When I am calling the LoadFromFile function with a word document over 4MB in size, it returns a System.OutOfMemoryException and I was wondering if there were any alternatives to this function e.g. multi-threading since I have tried both methods with different parameters. Any help would be appreciated.

Kind regards,
Adrian

adrianchan
 
Posts: 13
Joined: Fri Dec 10, 2021 2:08 am

Mon Jan 24, 2022 9:08 am

Hello,

Thanks for your inquiry!

To help us better investigate in your issue, could you please provide your input file and the following information to us? You can also send them to us via email(aupport@e-iceblue.com). Thanks in advance.

1. Your target framework(E.g. .Net5.0)
2. The project type (E.g. console app)
3. Your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese)
4. The version of Spire.Doc you were using.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Jan 24, 2022 9:42 am

Hello Marcia,

Here is the requested information:
1) .Net 4.8
2) MVC asp.net
3) Win10 64 bit, Hong Kong SAR - Chinese
4) FreeSpire.Doc 9.9.7

With regards to the input file, the problem persists in the fact that we are trying to generate several batches of document, which resulted in having to call the read/ write function recursively, which inevitably leads to memory leak.

Code: Select all
foreach(KeyValuePair<string, Document> entry in dictionary){
   ...
   saveDoc.LoadFromFile(path);
   foreach(Section sec in entry.Value.Sections) {
      saveDoc.Sections.Add(sec.Clone());
   }
   saveDoc.SaveToFile(path, FileFormat.Docx);
   saveDoc.Close();
   }
}


Kind regards,
Adrian

adrianchan
 
Posts: 13
Joined: Fri Dec 10, 2021 2:08 am

Mon Jan 24, 2022 10:04 am

Hello Adrian,

Thanks for sharing more information!

I simulated a project as the information you provided, and then load 4 files, each file is larger than 4MB, but still cannot reproduce your issue. Here are some methods for your try. First, please use document.Dispose(); to release the memory our product use after you finishing save. Or you can also change the solution platforms to X64, since x64 allows more memory space.

Besides, according to your code, do you want to merge two files to one document? If so, you can also use document.InsertTextFromFile("filepath", FileFormat.Docx); or document.InsertTextFromStream(stream, FileFormat.Docx); to achieve your needs.

If the issue still exists after trying these methods, I am afraid that this issue may relate to your input files. Please provide them to us for further investigate, we promise to keep your documents confidential, and we will not use it for any other purpose. Also, you could remove the security data of your Word as long as the modified files could reproduce your issue. Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Feb 09, 2022 7:18 am

Hello,

Hope you are doing well!

Has the issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.Doc