小编use*_*649的帖子

C#Excel自动化导致Excel内存泄漏

我正在尝试将C#与COM Interop库一起使用来打开一组非常繁重的Excel工作簿.我必须使用C#,因为我还需要启动宏,移动一些单元格,并启动我公司使用的自定义excel-add-in.

然后我的程序退出,打开工作簿,每个工作簿都在一个单独的excel实例中.我不希望在程序退出时关闭工作簿.

问题是当我的C#程序退出时,随着时间的推移,excel工作簿逐渐消耗更多的内存,直到他们从原来的500 MB消耗3.5 GB的内存.

我曾经手工打开工作簿,这些工作表从来没有消耗过那么多的记忆.一旦我开始使用C#打开它们,它们就会因极端内存使用而开始破解.我的理论是,不知何故,当我与COM Excel对象交互时,我创建了一个内存泄漏.

以下是我的原始代码:

using Excel = Microsoft.Office.Interop.Excel;
...
excelApp = new Excel.Application();
excelApp.Visible = true;
excelApp.Workbooks.Open(filename, misValue, misValue, misValue, misValue, misValue,
               true, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
excelApp.Calculation = Excel.XlCalculation.xlCalculationAutomatic;
Run Code Online (Sandbox Code Playgroud)

我读到了你需要如何使用Marshal来释放用途,所以我现在正在尝试以下代码,但没有简单的方法来测试它,除了打开所有工作表并查看它们是否消耗了太多数据.

            excelApp = new Excel.Application();
            excelApp.Visible = true;
            Excel.Workbooks currWorkbooks = excelApp.Workbooks;
            Excel.Workbook currWorkbook = currWorkbooks.Open(filename, misValue, misValue, misValue, misValue, misValue,
               true, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            //excelApp.Calculation = Excel.XlCalculation.xlCalculationAutomatic;

            int x = Marshal.ReleaseComObject(currWorkbook);
            currWorkbook = null;

            int …
Run Code Online (Sandbox Code Playgroud)

c# com excel automation interop

12
推荐指数
1
解决办法
5896
查看次数

如何在C NOT C++中将Mat转换为IplImage

我正在使用一些使用旧的弃用IplImage类型的旧C代码.

我正在使用新的OpenCV 2.3.1 for Android,我从相机获得的图像是CvMats.我想将它们转换为IplImage所以我可以将它传递给本机函数.

或者,我可以修改原始函数以接受a CvMat并将其转换IplImage为函数体内部,但我需要在C NOT C++中执行此操作.

c opencv matrix

1
推荐指数
1
解决办法
1364
查看次数

标签 统计

automation ×1

c ×1

c# ×1

com ×1

excel ×1

interop ×1

matrix ×1

opencv ×1