diff options
2 files changed, 21 insertions, 12 deletions
diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java index fb40f2c47aa..21d5317b8c7 100755 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/AbstractNattableWidgetManager.java @@ -275,6 +275,11 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan * the cell editor axis configuration */ private CellEditorAxisConfiguration cellAxisConfiguration; + + /** + * Keep the decoration service as variable to avoid possible memory leak. + */ + protected DecorationService decorationService; /** * The table popup menu configuration. @@ -650,17 +655,19 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan * the decoration service */ protected DecorationService getDecorationService() { - // Bug 490067: We need to check if the resource of the context is existing before to get the decoration service (to avoid useless log exception) - // The resource of the context is not existing in the case of deletion (EObject was already deleted but the reference of table always exists) - if (null != this.table.getContext().eResource()) { - try { - ServicesRegistry serviceRegistry = ServiceUtilsForEObject.getInstance().getServiceRegistry(this.table.getContext());// get context and NOT get table for the usecase where the table is not in a resource - return serviceRegistry.getService(DecorationService.class); - } catch (ServiceException e) { - Activator.log.error(e); + if(null == decorationService){ + // Bug 490067: We need to check if the resource of the context is existing before to get the decoration service (to avoid useless log exception) + // The resource of the context is not existing in the case of deletion (EObject was already deleted but the reference of table always exists) + if (null != this.table.getContext().eResource()) { + try { + ServicesRegistry serviceRegistry = ServiceUtilsForEObject.getInstance().getServiceRegistry(this.table.getContext());// get context and NOT get table for the usecase where the table is not in a resource + return serviceRegistry.getService(DecorationService.class); + } catch (ServiceException e) { + Activator.log.error(e); + } } } - return null; + return decorationService; } /** @@ -1331,6 +1338,9 @@ public abstract class AbstractNattableWidgetManager implements INattableModelMan if (this.filterStrategy instanceof IDisposable) { ((IDisposable) this.filterStrategy).dispose(); } + if(null != this.decorationService){ + this.decorationService = null; + } this.cellAxisConfiguration = null; this.filterConfiguration = null; this.tableEditingDomain = null; diff --git a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java index ea7d51ca73c..b733b0de9ce 100755 --- a/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java +++ b/plugins/infra/nattable/org.eclipse.papyrus.infra.nattable/src/org/eclipse/papyrus/infra/nattable/manager/table/NattableModelManager.java @@ -816,9 +816,8 @@ public class NattableModelManager extends AbstractNattableWidgetManager implemen public void dispose() { if (this.decoractionServiceObserver != null) { // Bug 490067: Check if the decoration service is available to avoid null pointer - final DecorationService decorationService = getDecorationService(); - if (null != decorationService) { - decorationService.deleteListener(this.decoractionServiceObserver); + if (null != this.decorationService) { + this.decorationService.deleteListener(this.decoractionServiceObserver); } this.decoractionServiceObserver = null; } |