Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
OutOfmemory problem - exporting a lot of data to Excel
posted

I've an OutOfmemory problem again.
Our customers are asking more and more data to export to Excel.
In the code below, the program is breaking during the loop or during the Save.
At that moment the error message 'OutOfmemory' is appearing.

Is there a way to avoid this?
Saving in between gives no solution. The memory stays increasing.
Can I avoid somehow that I need to much memory?
Also, I still need still to format some cells. This will also increase the request to memory.

I'm using :
Infragistics3.excel.v10.2 (v.10.2.20102.1004)
on a Windows XP with 2Gb of memory.

Here is the code :
------------------

Dim workbook As New Infragistics.Excel.Workbook(Infragistics.Excel.WorkbookFormat.Excel2007)
Dim wks As Infragistics.Excel.Worksheet = Nothing
Dim wksRow As Infragistics.Excel.WorksheetRow
Dim RowsCount As Integer = 0

workbook.SaveExternalLinkedValues = False
workbook.CalculationMode = Infragistics.Excel.CalculationMode.Manual
workbook.RecalculateBeforeSave = True

wks = workbook.Worksheets.Add("Sheet0")

With wks
  For rowi As Long = 1 To 150000

    RowsCount += 1
    wksRow = wks.Rows(rowi)
    With wksRow
     For i As Integer = 1 To 350
         .Cells(i).Value = "VALUE" & i & "-" & rowi
     Next
    End With
    wksRow = Nothing
  Next
End With
wks = Nothing

workbook.Save("c:\ABC11.xlsx")

 

Parents
No Data
Reply
  • 12773
    posted

    Hello,

    After we look at this issue more deeply with our development team and debug the sample I have created for this scenario based on your code and details we found that this error is caused by the fact that the sample is allocating unique strings to cells in 150,000 rows and 350 columns in each row. Each string is about 38 bytes.  That is 52,500,000 unique strings with 38 bytes each, or 1,995,000,000 bytes, or almost 2GB of memory which are only needed for string values. Also in addition, it creates 52,500,000 WorksheetCell instances, which are 24 bytes each. This accounts for 1.25GB of memory.
    And generally this is too much memory being used only for the strings data. So in this particular example the most of the memory is used for the real data and there is no way to be optimized if the memory of the computer is limited. This is more seen especially on XP machines.

    Let me know if you have any further questions.

    Sincerely,
    Dimi
    Developer Support Engineer
    Infragistics, Inc.

Children
No Data