Should I dispose CellEditor returned from EditingSupport.getCellEditor, and if so when should I do it.
On one of the tutorials on jface TableViewer I saw following snippet:
public class FirstNameEditingSupport extends EditingSupport {
@Override
protected CellEditor getCellEditor(Object element) {
return new TextCellEditor(viewer.getTable());
}
so would this method leak memory if cell was edited multiple times? Or should I just lazy initialize CellEditor:
public class FirstNameEditingSupport extends EditingSupport {
CellEditor editor;
@Override
protected CellEditor getCellEditor(Object element) {
if(editor == null){
editor = new TextCellEditor(viewer.getTable());
}
return editor;
}
The first snippet looks like a nasty leak to me if you use such a
EditingSupportforViewerColumns. Just have a look at the source of ColumnViewerEditor, the class handling lots of the work aroundCellEditors. There are lots of lines like(with
partbeing aViewerColumn). These calls create aTextinstance in the constructor of theTextCellEditor. But since theEditingSupportinstance is not assigned, it will be GCed immediately. TheTextinstance will not be disposed (until its parent is disposed). Leak.So your second snippet seems way better.
Which tutorial? Maybe you should report that.