Free Support Forum - aspose.com

Memory leak while doing CalculateFormula

Here is the code and the excel I am using to test. When I replace CalculateFormula line with Thread.Sleep(500), the code works perfectly. As soon as I put back CalculateFormula, memory grows to couple of Gigs and eventually throws OutofMemory Exception.

using System;
using System.Threading;
using Aspose.Cells;

namespace FeeTester
{
class Program
{
static void Main()
{
const int threadCount = 25;
var threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++)
{
threads[i] = new Thread(Call);
threads[i].Start(i);
Console.WriteLine("Started Thread " + (i + 1));
}

for (int i = 0; i < threadCount; i++)
threads[i].Join();

Console.WriteLine("Waiting for all Threads to finish");
Console.ReadLine();
}

static void Call(object input)
{
var wb = new Workbook(@"KY_Structure_v1.xlsx");

for(int i = 0; i < 1000; i++)
{
int index = wb.Worksheets.AddCopy("INPUT_OUTPUT");
Worksheet ws = wb.Worksheets[index];
ws.CalculateFormula(false, false, null); //Thread.Sleep(500);
wb.Worksheets.RemoveAt(index);
}
Console.WriteLine(string.Format("Thread - {0} is done", input));
}
}
}

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

If you are using multiple threads, then please use separate workbook object for each of your thread.

Otherwise, you will have to write your own synchronization code to keep your code thread safe.

Please also download and try the latest version: Aspose.Cells
for .NET v7.4.0.2
and let us know your feedback.

I am using different Workbook object in different thread. Please review the attached code. I have made sure that I am not using the same workbook object across threads.

Thanks

Hi,

Thanks for your feedback and using Aspose.Cells.

We have logged your code and requirements in our database. Please spare us some time. We will look into your issue and help or advise you asap.

This issue has been logged as CELLSNET-41387.

Hi,

Aspose.Cells created some internal data and objects for calculating
formulas.

As a .Net frame application, we did not directly control remove
them from memory and only GC could actually remove them from memory though they
are not referred .

So if calling Thread.Sleep(500); everything works
fine.

We are working on improving the performance of Aspose.Cells to reduce
the memory.