Aspose.Cells leads to OutOfMemoryException

Dear All

In our code we generate an excel workbook.

We uses Aspose.Cells v.4.4

Before Workbook.Save(fileName) is called garbage collector (GC.GetTotalMemory method) says that our application uses ~169Mb memory. Just after WorkBooks.Save(fileName) method is called the same method says that ~223Mb memory has been used. It means that sometimes we have OutOfMemoryException, when, for instance initially, the application works with a bigger report and uses more than 200Mb memory.

Here are a few results for Aspose.Cells. v.4.5:

Before Workbook.Save(fileName) is called: ~896Mb 8-(

After Workbook.Save(fileName) is called: ~976Mb

Please help us to solve the issue.

I have used the code from your site (CreateAsposeCellsFile1 method) with 20000 rows and 100 columns. The result file size is about 5Mb. How the same data can occupy > 200 Mb in memory? 8-(

Here are some detail test results:

=== Aspose.Cells, Version=4.4.0.0, Culture=neutral, PublicKeyToken=9a40d5a4b59e5256 ===
Start CreateAsposeCellsFile1 627208 b = 0 Mb
Workbook has been created 635400 b = 0 Mb
Before AutoFitRows 265125032 b = 252 Mb
Before Save 264400320 b = 252 Mb
After Save 376647516 b = 359 Mb
File Created!
Time consumed (Seconds): 112.346626

=== Aspose.Cells, Version=4.5.1.0, Culture=neutral, PublicKeyToken=716fcc553a201e56 ===
Start CreateAsposeCellsFile1 700936 b = 0 Mb
Workbook has been created 709128 b = 0 Mb
Before AutoFitRows 276634048 b = 263 Mb
Before Save 277682868 b = 264 Mb
After Save 461774320 b = 440 Mb
File Created!
Time consumed (Seconds): 99.4869218

Please help me to solve the issue.

Hi,

Could you create a sample console application (using 4.5.1) to show the issue, we will check it soon.

Thank you.

Dear Amjad

Thank you for the response.

Below is the code which is used for testing purposes. Please take a look.

class Program

{

private static bool _useAutoFit = true;

private static bool _provideMemoryInfo = true;

static void Main(string[] args)

{

Assembly assembly = Assembly.LoadFrom("Aspose.Cells.dll");

Console.WriteLine(assembly.FullName);

String time = DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss_tt");

CreateAsposeCellsFile1(String.Format("test2_{0}", time));

}

private static void ProvideMemoryInfo(String message)

{

if (_provideMemoryInfo)

{

if (!String.IsNullOrEmpty(message))

{

Console.WriteLine(message);

}

long bytes = GC.GetTotalMemory(false);

Console.WriteLine(String.Format("{0} b = {1:N0} Mb", bytes, bytes/1024/1024));

}

}


private static void CreateAsposeCellsFile1(string filename)

{

DateTime start = DateTime.Now;

ProvideMemoryInfo("Start CreateAsposeCellsFile1");

Workbook workbook = new Workbook();

Worksheet ws = workbook.Worksheets[0];

ProvideMemoryInfo("Workbook has been created");

for (int row = 0; row < 20000; row++)

{

for (int col = 0; col < 100; col++)

{

ws.Cells[row, col].PutValue(row + "," + col);

}

}

if (_useAutoFit)

{

ProvideMemoryInfo("Before AutoFitRows");

ws.AutoFitRows();

}

ProvideMemoryInfo("Before Save");

workbook.Save(filename + ".xls");

ProvideMemoryInfo("After Save");

DateTime end = DateTime.Now;

TimeSpan time = end - start;

Console.WriteLine("File Created! \n" + "Time consumed (Seconds): " + time.TotalSeconds);

}

}

Hi,

Thanks for providing us the sample project.

Well, I have checked your project a bit, the generated file is actually 50Mb not 5Mb, which is some size you know and the process will certainly consume certain memory and take some time to be completed. I get almost similar readings you provide.When you do need to create a huge excel file, it will require certain memory and resources. We recommend you to try to split your data into multiple worksheets instead of filling data into a single worksheet, it will certainly enhance performance and consume less memory / resources.

We will further look into it soon.

Thank you.

Dear Amjad

You are right the file size is about 50Mb. Unfortunately, it uses a lot of memory.

Anyway, thank you for your recommendations.

Hi,

We have enhanced the performance of saving the larger files. Following is the new test result with the attached version on one of our machines, the memory utilization is decreased.

Start CreateAsposeCellsFile1
150476 b = 0 Mb
Workbook has been created
302640 b = 0 Mb


Before AutoFitRows
276505040 b = 263 Mb
Before Save
276165660 b = 263 Mb

After Save
254626396 b = 371 Mb
File Created!
Time consumed (Seconds): 47.234375

Could you try the attached version.

Thank you.

Dear Amjad

It looks like the attached DLL works better. Here are new results:

=== Aspose.Cells, Version= 4.5.1.19 , Culture=neutral, PublicKeyToken=716fcc553a201e56 ===

Start CreateAsposeCellsFile1 708996 b = 0 Mb

Workbook has been created 717188 b = 0 Mb

Before AutoFitRows 254573876 b = 242 Mb

Before Save 256215604 b = 244 Mb

After Save 337268816 b = 321 Mb

File Created!

Time consumed (Seconds): 41.6636875

I am going to verify it with live data.

Dear Amjad

It works with the real data as well. Now we’re going to update our production version, so could you suggest when this hotfix will be added to the stable version, 4.5.2 for example?

Hi,

Ok, We will give you an eta for our next official release (Aspose.Cells for .NET) soon.

Thank you.

Hi,

Hopefully, we can release it within a week or so.

Thank you.

The issues you have found earlier (filed as 6749) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Laurence.