diff options
| author | Pierre-Charles David | 2016-10-28 09:54:22 +0000 |
|---|---|---|
| committer | Pierre-Charles David | 2016-12-13 08:58:34 +0000 |
| commit | b4b937dac3190f416cd482eaf8ca5993a4d56b36 (patch) | |
| tree | bd96296d7a29b5f47f5ba5ee22b84c0b9566072b | |
| parent | a5b514cf20e93dbddd3fac34bcfc236ad9c3d44c (diff) | |
| download | org.eclipse.sirius-b4b937dac3190f416cd482eaf8ca5993a4d56b36.tar.gz org.eclipse.sirius-b4b937dac3190f416cd482eaf8ca5993a4d56b36.tar.xz org.eclipse.sirius-b4b937dac3190f416cd482eaf8ca5993a4d56b36.zip | |
[501263] Fix memory leak in DDiagramEditorImpl
This applies to DDiagramEditorImpl the same approach as commit
bb18387550e27d3e0f5d41c94d35fc03730b517c did to the tree/table editors,
i.e. replace anonymous inner class (which has a hidden pointer to the
enclosing DDiagramEditorImpl) with a static internal class which cleans
it reference to the editor once it does not need it anymore.
Bug: 501263
Change-Id: I5d017a2708bdfbf146d754b3a93d99780991a302
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
| -rw-r--r-- | plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java index 7cf6eb0181..37a1ec05e3 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java @@ -230,6 +230,43 @@ import com.google.common.collect.Sets; * @since 0.9.0 */ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramEditor, ISelectionListener, SessionListener { + /** + * 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 DDiagramEditorImpl editor; + + public SessionHandlingForEditor(DDiagramEditorImpl 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); + /* + * need to reinit command factory provider to take the right + * model accesor + */ + editor.initCommandFactoryProviders(); + // 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); + } + } + } protected class DDiagramEditorTransferDropTargetListener extends AbstractTransferDropTargetListener { @@ -329,26 +366,7 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE private IAuthorityListener dRepresentationLockStatusListener; - private 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(DDiagramEditorImpl.this); - /* - * need to reinit command factory provider to take the right - * model accesor - */ - initCommandFactoryProviders(); - /* remove this listener */ - SessionManager.INSTANCE.removeSessionsListener(this); - } - } - }; + private final SessionManagerListener sessionManagerListener = new SessionHandlingForEditor(this); private TabbarRefresher tabbarPostCommitListener; |
