使用EPPlus Excel库时巨大的内存分配 [英] Huge memory Allocation when using EPPlus Excel Library
问题描述
新单元格存储
*减少内存消耗
*插入列(不在范围级别)
*更快的行插入
在更新Nuget之后,我仍然有同样的异常,这是在第一行之后抛出的,而不是在第二行被引发。
现代Excel文件,即Xlsx文件是zip压缩的,经常实现压缩降低到10%。我刚解压缩了我使用类似工具生成的1.6MB文件,并将其解压到18.8 MB的数据。
您有一个0.138 GB的文件,使用1.370 GB的内存,几乎正好是10%。记忆中的未压缩的表现是什么在吃你的记忆。
如果你好奇,你可以使用一个像7-Zip这样的工具来提取Xlsx文件,或者你可以将文件重命名为.zip结尾并在Windows中浏览。
Context
I have been using EPPLUS as my tool to automate excel report generation, using C# as the client language of the library.
Problem:
After trying to write a really big report (response of a SQL Query), with pivot tables, charts and so forth, i end up having a Out of Memory Exception
.
TroubleShooting
In order to troubleshoot, i decided to open an existing report that has 138MB, and use the GC
object to try to take a peek on what's happening with my memory, and here are the results.
ExcelPackage pkg = new ExcelPackage (new FileInfo (@"PATH TO THE REPORT.xlsx"));
ExcelWorkbook wb = pkg.Workbook;
Garbage Collection Results, before the second line of code, and after.
So, i have no idea what to do from now on. All i am doing is opening the report, which is consuming roughtly 10 (9.98 actually) times the report size itself, on memory.
The ~138MB of the excel file, takes up 1.370.817.264 bytes of RAM.
Update One:
There's a fairly recent beta version of EPPlus that's out that has on it's changelog:
New Cell store
* Less memory consumtion
* Insert columns (not on the range level)
* Faster row inserts
After updating the Nuget, i still have the same exception, that is thrown after the first line, instead of being raised on the second line.
Modern Excel files, ie, Xlsx files are zip-compressed, and often achieve compression down to 10%. I just uncompressed a 1.6MB file I generated using a similar tool and found it extracted to 18.8 MB of data.
You've got a 0.138 GB file that is using 1.370 GB of memory, which is almost exactly 10%. The uncompressed representation in memory is what is eating your memory.
If you're curious, you can use a tool like 7-Zip to extract the Xlsx files, or you can rename the file to end in .zip and browse it in Windows.
这篇关于使用EPPlus Excel库时巨大的内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!