问题是我如何配置 Infragistics 网格。答案也记录在此链接中:
http://www.infragistics.com/community/forums/t/56315.aspx
导致OOM问题的代码是:
private static void ConfigureDeleteColumnOn(UltraGridBand band)
{
band.Columns.Add(DELETE_BUTTON);
band.Columns[DELETE_BUTTON].EditorControl = GetDeleteButtonEditor();
}
private static Control GetDeleteButtonEditor()
{
UltraTextEditor editor = new UltraTextEditor();
EditorButton btn = new EditorButton
{
Appearance =
{
Image = Resources.Resources.delete,
ImageBackgroundStyle = ImageBackgroundStyle.Centered
}
};
editor.EditorButtonClick += editor_EditorDeleteButtonClick;
editor.ButtonsLeft.Add(btn);
return editor;
}
此代码强制网格为每个单元格创建一个新的位图。有 11000 行,网格尝试创建 11000 个位图并导致 OOM 异常。
解决方案是:
private static void ConfigureDeleteColumnOn(UltraGridBand band)
{
band.Columns.Add(DELETE_BUTTON);
band.Columns[DELETE_BUTTON].ButtonDisplayStyle = ButtonDisplayStyle.Always;
band.Columns[DELETE_BUTTON].Style = ColumnStyle.Button;
band.Columns[DELETE_BUTTON].CellButtonAppearance.Image = Resources.Resources.delete;
}