How can I solve out of memory exception in generic list generic?
How can i solve out of m开发者_开发问答emory exception in list generic if adding new value
foreach(DataColumn dc in dTable.Columns)
foreach (DataRow dr in dTable.Rows)
myScriptCellsCount.MyCellsCharactersCount.Add(dr[dc].ToString().Length);
MyBase Class:
public class MyExcelSheetsCells
{
public List<int> MyCellsCharactersCount { get; set; }
public MyExcelSheetsCells()
{
MyCellsCharactersCount = new List<int>();
}
}
Use fewer rows and columns. Right now you're creating a new entry in MyCellsCharacterCount
for the number of rows times the number of columns, which could pretty easily exceed the amount of available memory if you have a lot of data.
If your table is simply too large for your column * row data, perhaps performing whatever meaningful operation/aggregation you're after (avg, sum, min, max, etc) would be better than simply saving off the counts individually.
Essentially, get a summary view instead of a detail view.
By your example, I have no way of guesstimating what you're after as what you're showing is simply storing the column-major count of characters.
JS Bangs' answer is giving you the reason, but neither of us can really give you an answer to your question without more information.
精彩评论