View Variables / Ram for .NET?

I am using Office Automation in .NET. It leaves the excel.exe program. I know of a fix - it's all about explicitly defining variables. Once determined, I can properly de-allocate the RAM and the GC will clear them.

The problem is that I have literally thousands of lines of code. So I'm wondering: is there some utility in .net (or third party) that is capable of showing me a list of variables that I am still allocating RAM for? If so, I will be able to target these elements and highlight them specifically.

thank

Ryan

+1


source to share


2 answers


http://www.automatedqa.com/techpapers/net_allocation_profiler.asp



+1


source


To be clear, you need to explicitly exit Excel after you are done with automation. If you don't use an instance, it will continue to run even if your variables go out of scope and trigger garbage collection. I believe the Quit () command is:

Excel.ApplicationClass excel = new Excel.ApplicationClass();
//do some work with Excel
excel.Quit();

      



I would recommend you do it with try / catch / finally

Excel.ApplicationClass excel = null;

try
{
  excel = new Excel.ApplicationClass();
  //do some Excel work
}
catch(Exception ex)
{
  //log exception
  throw;
}
finally
{
  if(excel != null)
    excel.Quit();
}

      

0


source







All Articles