Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Closed Unassigned: Excessive memory usage, bug? [9395]

$
0
0
Hi

We are using ClosedXML to generate reports with multiple millions of cells and our memory usage just goes through the roof.

As a rule of thumb ClosedXML needs around 100 times the memory a generated .xslx has in size.

Am I doing something wrong? Is there a way to reduce the memory usage besides disabling event tracking?
The whole thing is just straight forward filling of cells, one row at the time. No inserting, moving, styling etc

I can replicate this on a little console application.
```
private static void CreateWorkbook()
{
Random rnd = new Random();
using (XLWorkbook workbook = new ClosedXML.Excel.XLWorkbook(XLEventTracking.Disabled))
{
using (var sheet = workbook.AddWorksheet("Result"))
{
for (int rowNumber = 1; rowNumber < 10000; rowNumber++)
{
using (var row = sheet.Row(rowNumber))
{
for (int columnNumber = 1; columnNumber < 300; columnNumber++)
{
row.Cell(columnNumber).Value = rnd.Next();
}
}
if (rowNumber % Percentage == 0)
Console.Write("\r{0}%", rowNumber / Percentage);
}

Console.Write("\r100%");
string savePath = Path.Combine(@"C:\temp\closedxml\", string.Format("{0}-report.xlsx", DateTime.UtcNow.ToString("yyyy-MM-dd-HH-mm-ss")));
workbook.SaveAs(savePath);
}
}
}
```
This generates a file of about 26MB for which around 2.6GB of memory is needed.

Thanks for any feedback, hints & tips.

St
Comments: 2.6GB to process 3 million cells is the price you pay for all the niceties ClosedXML has to offer. btw, it's 26MB compressed so the file is actually 162MB.

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>