NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

Get Excel cell value memory leak issues #336

Closed susson closed 2 years ago

susson commented 2 years ago

Hello,

I found a suspected memory leak problem, as shown in the following code(COMAddin Ribbon):

public void btnGetValue(Office.IRibbonControl control)
{
    var wbk = Application.ActiveWorkbook;

    var wsh = wbk.Sheets[1] as Excel.Worksheet;
    for (int j = 0; j < 10; j++)
    {
        for (int i = 1; i <= 10000; i++)
        {
            Console.WriteLine(wsh.Range("A"+i).Value.ToString());
        }
    }
   MessageBox.Show("OK");
}

Memory usage will continuous increase, I suspect there is a memory leak. Could you please analyze it for me? Thanks!

jozefizso commented 2 years ago

Hi @susson, I recommend the ReSharper dotMemory tool to analyze memory leaks. It will show you detailed data where the allocations come from and which objects are held in memory.

susson commented 2 years ago

Thank you, I'll have a try.