diff options
| author | Pierre-Charles David | 2016-09-12 14:36:25 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-10-27 08:26:14 +0000 |
| commit | 7ced4bd44b5c036f7b1c7fed8627680efbe4d3d4 (patch) | |
| tree | b6358ee8c1436b4e5d3cc2c95496d48131afb490 | |
| parent | 23c6be2da7215b3cf300eac31470b62635f59a5c (diff) | |
| download | org.eclipse.sirius-7ced4bd44b5c036f7b1c7fed8627680efbe4d3d4.tar.gz org.eclipse.sirius-7ced4bd44b5c036f7b1c7fed8627680efbe4d3d4.tar.xz org.eclipse.sirius-7ced4bd44b5c036f7b1c7fed8627680efbe4d3d4.zip | |
[506082] Cleanup DTreeEditor references on disposal
A disposed editor can still be referenced by parts of the Eclipse
runtime (e.g. in ContextService.UpdateExpression via an
ActivePartExpression), so it is important to cleanup all the references
we keep on large structures (models, the session) when disposed to avoid
memory leaks.
Bug: 506082
Change-Id: I6ae213bedb249e671ea3b60e0132014d110db051
Cherry-picks: bb18387550e27d3e0f5d41c94d35fc03730b517c
Cherry-picks: d7b5834511b4ba3ce259f47daf0bcf2e0a1e304b
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
4 files changed, 52 insertions, 29 deletions
diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/api/editor/AbstractSpecificDTableEditor.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/api/editor/AbstractSpecificDTableEditor.java index f07dd96121..4958b3030d 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/api/editor/AbstractSpecificDTableEditor.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/api/editor/AbstractSpecificDTableEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -33,27 +33,21 @@ public abstract class AbstractSpecificDTableEditor extends AbstractDTableEditor private SpecificEditorInputTranformer util = new SpecificEditorInputTranformer(); - /** - * {@inheritDoc} - */ @Override public void dispose() { super.dispose(); - util.cleanEnvironment(); + if (util != null) { + util.cleanEnvironment(); + util = null; + } } - /** - * {@inheritDoc} - */ @Override public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { util.init(getViewpointURI(), getDiagramDescriptionName()); super.init(site, util.transformInput(input, getSelection(site), isSessionStoredInWorkspace())); } - /** - * {@inheritDoc} - */ @Override public void setInput(IEditorInput input) { super.setInput(util.transformInput(input, getSelection(getSite()), isSessionStoredInWorkspace())); diff --git a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java index 60d9e6ac01..ca7e6fafaa 100644 --- a/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java +++ b/plugins/org.eclipse.sirius.table.ui/src/org/eclipse/sirius/table/ui/tools/internal/editor/AbstractDTableEditor.java @@ -489,10 +489,10 @@ public abstract class AbstractDTableEditor extends AbstractDTreeEditor implement @Override public void dispose() { - super.dispose(); if (getAdapterFactory() instanceof IDisposable) { ((IDisposable) getAdapterFactory()).dispose(); } + super.dispose(); if (refreshAtOpeningActivator != null) { getSite().getPage().removePartListener(refreshAtOpeningActivator); refreshAtOpeningActivator = null; diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java index 54d1c03b8d..7e3ac42d5b 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/DTreeEditor.java @@ -463,10 +463,11 @@ public class DTreeEditor extends AbstractDTreeEditor implements org.eclipse.siri getSite().getPage().removePartListener(refreshAtOpeningActivator); } refreshAtOpeningActivator = null; - super.dispose(); if (getAdapterFactory() instanceof IDisposable) { ((IDisposable) getAdapterFactory()).dispose(); } + super.dispose(); + treeModel = null; } /** diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java index 11913ed14c..81dc6f163a 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/editor/AbstractDTreeEditor.java @@ -94,6 +94,40 @@ import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributo public abstract class AbstractDTreeEditor extends EditorPart implements DialectEditor, IViewerProvider, ITabbedPropertySheetPageContributor, IEditingDomainProvider, IReusableEditor, SessionListener, ISaveablesSource, IPageListener { + /** + * This class has the responsibility to open the editing session + * corresponding to a session added to the session manager and attaching to + * it the current editor so it can be handled correctly. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ + private static final class SessionHandlingForEditor extends SessionManagerListener.Stub { + private AbstractDTreeEditor editor; + + public SessionHandlingForEditor(AbstractDTreeEditor editor) { + this.editor = editor; + } + + @Override + public void notifyAddSession(final Session newSession) { + + /* we want to be notified only once */ + final IEditingSession editingSession = SessionUIManager.INSTANCE.getOrCreateUISession(newSession); + if (!editingSession.isOpen()) { + editingSession.open(); + editingSession.attachEditor(editor); + // important to remove the reference to the editor because this + // listener is still referenced by Eclipse ContextService when + // the editor is closed causing a leak. + editor = null; + /* remove this listener */ + SessionManager.INSTANCE.removeSessionsListener(this); + } + + } + } + /** The PERMISSION_GRANTED_TO_CURRENT_USER_EXCLUSIVELY icon descriptor. */ private static final ImageDescriptor LOCK_BY_ME_IMAGE_DESCRIPTOR = SiriusEditPlugin.Implementation .getBundledImageDescriptor("icons/full/decorator/permission_granted_to_current_user_exclusively.gif"); //$NON-NLS-1$ @@ -148,21 +182,7 @@ public abstract class AbstractDTreeEditor extends EditorPart /** * SessionManagerListener. */ - protected final SessionManagerListener sessionManagerListener = new SessionManagerListener.Stub() { - @Override - public void notifyAddSession(final Session newSession) { - - /* we want to be notified only once */ - final IEditingSession editingSession = SessionUIManager.INSTANCE.getOrCreateUISession(newSession); - if (!editingSession.isOpen()) { - editingSession.open(); - editingSession.attachEditor(AbstractDTreeEditor.this); - /* remove this listener */ - SessionManager.INSTANCE.removeSessionsListener(this); - } - - } - }; + protected final SessionManagerListener sessionManagerListener = new SessionHandlingForEditor(this); /** * The DialectEditorDialogFactory. @@ -586,6 +606,7 @@ public abstract class AbstractDTreeEditor extends EditorPart if (dRepresentationLockStatusListener != null) { IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(getRepresentation()); permissionAuthority.removeAuthorityListener(dRepresentationLockStatusListener); + dRepresentationLockStatusListener = null; } isClosing = true; @@ -595,10 +616,12 @@ public abstract class AbstractDTreeEditor extends EditorPart if (this.undoRedoActionHandler != null) { this.undoRedoActionHandler.dispose(); } + undoRedoActionHandler = null; super.dispose(); if (getTableViewer() != null) { getTableViewer().dispose(); } + treeViewerManager = null; // We need to perform the detachEditor after having disposed the viewer // and the editor input to avoid a refresh. A refresh can occurs in the // case where the detach triggers the reload of the modified resources @@ -609,8 +632,13 @@ public abstract class AbstractDTreeEditor extends EditorPart if (sess != null) { sess.detachEditor(this, choice == ISaveablePart2.NO); } + session = null; } - + adapterFactory = null; + accessor = null; + currentPropertySheetpage = null; + emfCommandFactory = null; + myDialogFactory = null; } @Override |
