Out of Memory Exception in Excel AddIn

M

Mk23

Hi

I'm programming an excel (Ver. 2007) addin in c#. The addin connect to a
database and set up a graphical dashboard for the data, by manipulating the
graphical style of a huge number of cells.

The problem is that the amount of memory is just increasing, so that i get a
out of memory exception. I thought that i do the releasing of the COM Object
right, but it doesn't work (see Code snippet). Also a call to GC.Collect()
doesn't help.

protected void SetBorder(Excel.Range rng, Excel.XlBordersIndex
borderType)
{
Excel.Borders borders = rng.Borders;
Excel.Border border = borders.get_Item(borderType);
border.LineStyle = Excel.XlLineStyle.xlContinuous;
border.Weight = Excel.XlBorderWeight.xlHairline;
border.ColorIndex = 1;
Marshal.ReleaseComObject(border);
Marshal.ReleaseComObject(borders);
border = null;
borders = null;
}

What can i do to save memory?

Best regards
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top