This project has moved and is read-only. For the latest updates, please go here.

How to Dispose Cells from Memory

Jul 8, 2013 at 5:37 AM
This is a great library for Excel.

But it came to situation when i have to read file and then dispose objects.
The code is like below.
The scenario is I read from Excel file as below.
So the problem is even this function completes the memory is not released back which makes me
very near to "OutofMemory" if function run multiple times.
So is there any way to dispose objects.
            System.IO.FileInfo objFileInfo = new System.IO.FileInfo(sFilepath);
            Stream strTemp = null;

            using (strTemp = objFileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (ExcelPackage objExcelPackage = new ExcelPackage())

                    ExcelWorkbook objExcelWorkbook = objExcelPackage.Workbook;

                    nSheetCount = GetWorkSheetCount(objExcelWorkbook);

                    for (int nIdx = 1; nIdx <= nSheetCount; nIdx++)
                        ExWorkSheet objExWorkSheet = new ExWorkSheet();
                        ExcelWorksheet objExcelWorksheet = objExcelWorkbook.Worksheets[nIdx];
                        objExWorkSheet.WorkSheetName = objExcelWorksheet.Name;
                        objExWorkSheet.UsedRange = GetUsedRange(objExcelWorksheet);

                        if (objExWorkSheet.UsedRange == null)
                            objExWorkSheet.Cells = new Dictionary<string, ExCell>();
                            lstExWorkSheet[nIdx - 1] = objExWorkSheet;

                        objExWorkSheet.Columns = GetColumns(objExcelWorksheet, objExWorkSheet.UsedRange);

                        objExWorkSheet.Rows = GetRows(objExcelWorksheet, objExWorkSheet.UsedRange);

                        objExWorkSheet.Cells = GetCells(objExcelWorksheet, objExWorkSheet.UsedRange);