Memory increase everytime I open a workbook without decreasing

Hi,

I know this concern has been brought up by many people but so far I did not get the good answer.
I built a very simple dotnet core webapi which convert an 8MB.xlsx file to workbook (Just convert and I won’t do any else rather than that)
As I observed by getting the WorkSet64 of the current process. The memory jumped from 63 to 650 for the first workbook. I kept calling the API after 20 times, it soared to more than 1GB. The bad thing is it never went down which make me extremely worry about how to build my API without having to reset it. (It’s weird rite?)

Attached is my sample code.SampleApi.zip (9.1 KB)

Sample file 8MB.zip (8.0 MB)

@KevinNg,

We were able to observe the issue simply using sample code below but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

static void main()
{
    DisplayMemorysizeOfCurrentProcess("Before conversion");
    GetOrCreateWorkbook();
    DisplayMemorysizeOfCurrentProcess("After conversion");
}
static void GetOrCreateWorkbook()
{
    using (var ms = new FileStream(@"8MB.xlsx", FileMode.Open, FileAccess.Read))
    {
        var wb = new Workbook(ms);
        var bytes = wb.SaveToStream().ToArray();
        DisplayMemorysizeOfCurrentProcess("convert to workbook");
        ms.Close();
        ms.Dispose();
    }
    GC.Collect();
}
private static long DisplayMemorysizeOfCurrentProcess(string prefix)
{
    long totalBytesOfMemoryUsed = 0;
    using (Process currentProcess = System.Diagnostics.Process.GetCurrentProcess())
    {
        //Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
        totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
        Console.WriteLine(DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss") + $"- {prefix} - Memory consumed:" + totalBytesOfMemoryUsed / (1024 * 1024));
    }
    return totalBytesOfMemoryUsed / (1024 * 1024);
}

This issue has been logged as

CELLSNETCORE-12 - Memory increased permanently while converting workbook to byte array using SaveToStream

Thank you,
Hope to hear from you guys soon.

@KevinNg,

As this issue is just logged so it may take a couple of weeks to resolve this issue. We will write back here once any feedback is ready to share.

@Kevinng85,

If you call “GC.Collect();”, you still need to wait for GC to release memory, the result may not be effect immediately. And you need to release “Workbook” class.
Please try below code, the memory release would be better (from 210MB down to 90MB).
And, there are still about 75MB memory might be occupied by static params.

    static void GetOrCreateWorkbook()
    {
        using (var ms = new FileStream(@"8MB.xlsx", FileMode.Open, FileAccess.Read))
        {
            var wb = new Workbook(ms);
            //var bytes = wb.SaveToStream().ToArray();
            MemoryStream mem = wb.SaveToStream();
            byte[] bytes = mem.ToArray();
            DisplayMemorysizeOfCurrentProcess("convert to workbook");
            //ms.Close();
            //ms.Dispose();
            bytes = null;
            mem.Close();
            mem.Dispose();
            wb.Dispose();
        }
        GC.Collect();
        GC.WaitForPendingFinalizers();
    }  

Let us know your feedback.

@Kevinng85,

This is to inform you that we have fixed your issue (logged earlier as “CELLSNETCORE-12”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.