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.

Fri May 13, 2022 7:14 am

Hello, I used next code provided bellow for generate large report from template(with one page). How it's work => I load template and for each iteration replace neccessary information, after that i increase pages(section on result document) and repeat this operation for all cyrcle. Result report including 11000 pages. And it's work amazing, no more 10 minutes and spend no more 50mb physical memory on disk for output document. But all the time this proccess working my system spend more than 30GB RAM. And it's looks like memory leaks, but I'm not sure. Because when i repeat process it's can increase using ram to plus 2GB, but from sometime GC some clear it. But average using ram on long time equal 30GB. Me need any Feedback about this, maybe I can improve my solution, maybe it's work something wrong. Any help from you're side, thanks.

My code was based on code from this sample: Spire.Doc-Program-Guide/Others/Preserve-Theme-When-Copying-Sections-from-One-Word-Document-to-Another-in-C.html

Code: Select all
            using var stream = new MemoryStream(fileBytes); // byte[]
            Document buffer = new Document(stream,true);
            Document doc = new Document(true);

            foreach (var placeholder in placeholders) // List<List<Pair<pattern, value>>>
            {
                foreach (var item in placeholder)
                {
                    buffer.Replace(item.Placeholder, item.Value.ToString(), false, true);
                }

                doc.Sections.Add(buffer.Sections[0].Clone()); // add prepared page
                buffer = new Document(stream, true);           // clear buffer or return to template condition
            }
            placeholders.Clear();
            doc.SaveToFile("compressed.pdf"); //50MB Physical Disk size, no more 15min Elapsed time

Mikhail.Marynakou
 
Posts: 3
Joined: Thu May 12, 2022 10:29 am

Fri May 13, 2022 11:27 am

Hello,

Thanks for your inquiry.
As for your situation. You can first try the following suggestions.
1. Our latest version is Spire.Doc Pack(hot fix) Version:10.4.6, if you were using an old version, you can try again with this latest one.
2. Calling close() and dispose() methods in your code.

If your issue still exists after trying, please share us with the listed more details, then we will do an accurate investigation.
1. Your system information (E.g. Win10, 64 bit, RAM:8GB) and the region setting (E.g. China, Chinese).
2. Save the buffer stream to a word file and share it with us. You can attach it here or send it to us via email( support@e-iceblue.com).

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 194
Joined: Mon Dec 27, 2021 2:23 am

Sun May 15, 2022 10:08 pm

Hello again, i think that, me need you're help. I simplified case. It's bad work with RAM usage for case copy one page to document with 10'000 pages. I think that problem related with Clone() or adding section. It's look as Document class saves very much additional information and don't release it's later.

Code: Select all
           
            Document buffer = new Document("test.docx", true);
            Document doc = new Document(true);
            for (int i = 0; i < 10000; i++  )
            {
                doc.Sections.Add(buffer.Sections[0].Clone());                  // how I understand this is bottleneck place
                buffer.Close();                                                                //  without changes (not working)
                buffer.Dispose();                                                             //  without changes (not working)
                buffer = new Document(templatePath, true);
            }
            doc.SaveToFile("compressed.pdf");
            doc.Close();                                                                        //  without changes (not working)
            doc.Dispose();                                                                    //  without changes (not working)


I provide test document. For me important first case I described, but currently i See that library bad work with large documents and I hope that it would help to make it better
test.zip



Windows 10 Version 10.0.19044 Build 19044 x64
Processor Intel(R) Core(TM) i9-9900 CPU @ 3.10GHz, 3096 Mhz, 8 Core(s), 16 Logical Processor(s)
Installed Physical Memory (RAM) 32,0 GB
Spire.Doc Pack(hot fix) Version:10.4.6

Mikhail.Marynakou
 
Posts: 3
Joined: Thu May 12, 2022 10:29 am

Mon May 16, 2022 11:23 am

Hello,

Thanks for your inquiry.
I used the following modified code to test your file, the memory consumption spent about 3GB. It's not as high as you used. Anyway, I have logged this issue into our tracking system by using SPIREDOC-7837. Our Dev team will further investigate and check the optimized solution. Once there is any progress, we will let you know asap.
Code: Select all
Document buffer = new Document(@"test.docx",true);
Document doc = new Document(true);
for (int i = 0; i < 10000; i++)
{
    doc.Sections.Add(buffer.Sections[0].Clone());   
}
doc.SaveToFile("compressed.pdf");
buffer.Close();                                     
buffer.Dispose();
doc.Close();                                         
doc.Dispose();

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 194
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Doc