DXWIN0002: Redundant RepositoryItem Initialization
Severity: Error
Avoid intializing new instances of repository items (RepositoryItem class descendants) inside frequently fired events. In certain cases, the Garbage Collector cannot collect such items.
Instead, use a variable to initialize required repository items outside event handlers.
Example 1
Invalid Code
private void GridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) {
RepositoryItemTextEdit edit = new RepositoryItemTextEdit();
edit.EditValueChanged += Edit_EditValueChanged;
e.RepositoryItem = edit;
}
Valid Code
// Store edit in a variable
RepositoryItemTextEdit edit = new RepositoryItemTextEdit();
edit.EditValueChanged += Edit_EditValueChanged;
private void GridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) {
e.RepositoryItem = edit;
}
Example 2
Invalid Code
private void GridView1_CustomRowCellEditForEditing(object sender, CustomRowCellEditEventArgs e) {
RepositoryItemTextEdit edit = new RepositoryItemTextEdit();
edit.EditValueChanged += Edit_EditValueChanged;
e.RepositoryItem = edit;
}
Valid Code
// Store edit in a variable
RepositoryItemTextEdit edit = new RepositoryItemTextEdit();
edit.EditValueChanged += Edit_EditValueChanged;
private void GridView1_CustomRowCellEditForEditing(object sender, CustomRowCellEditEventArgs e) {
e.RepositoryItem = edit;
}