Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-11-15 15:59:32 +0000
committerChristian W. Damus2014-11-15 15:59:32 +0000
commit4ce552bd5e30f589bd4ad3e313db3b573a73089c (patch)
treea7bff60f24e89304e3359f5709e8bf53c2a010ef
parentd0557a86e852fd7ae0d3d428380d2fdf9b3733d5 (diff)
downloadorg.eclipse.papyrus-4ce552bd5e30f589bd4ad3e313db3b573a73089c.tar.gz
org.eclipse.papyrus-4ce552bd5e30f589bd4ad3e313db3b573a73089c.tar.xz
org.eclipse.papyrus-4ce552bd5e30f589bd4ad3e313db3b573a73089c.zip
451683: Memory leak in stereotype repair
https://bugs.eclipse.org/bugs/show_bug.cgi?id=451683 Fix memory leaks in: - the common navigator framework (Model Explorer) - the Papyrus EMF Facet tree content provider (Model Explorer) - the GMF diagram outline page (SynchronizableGmfDiagramEditor)
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java4
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java91
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java16
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java21
4 files changed, 124 insertions, 8 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
index ead389ac0df..c6e86d7115a 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedTreeContentProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Mia-Software, CEA, and others.
+ * Copyright (c) 2012, 2014 Mia-Software, CEA, Christian W. Damus, 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
@@ -13,6 +13,7 @@
* Christian W. Damus (CEA) - bug 440795
* Christian W. Damus (CEA) - bug 441857
* Sebastien Gabel (Esterel Technologies) - Bug 438931 - Non deterministic order of the facet references defined in custom file
+ * Christian W. Damus - bug 451683
*
*******************************************************************************/
package org.eclipse.papyrus.emf.facet.custom.ui.internal;
@@ -503,5 +504,6 @@ public class CustomizedTreeContentProvider implements ICustomizedTreeContentProv
public void dispose() {
cache.clear();
+ rootElements = null;
}
} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
index dd03f4261d3..7536da5fc98 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java
@@ -1,6 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
+ * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,6 +9,7 @@
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 437217
+ * Christian W. Damus - bug 451683
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common;
@@ -30,6 +30,7 @@ import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.ui.palette.PaletteViewer;
+import org.eclipse.gef.ui.parts.ContentOutlinePage;
import org.eclipse.gef.ui.views.palette.PalettePage;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
@@ -45,6 +46,8 @@ import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.commands.CheckedDiagramCommandStack;
@@ -64,9 +67,12 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.part.IPageBookViewPage;
import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -202,6 +208,13 @@ public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor implem
palettePages.add(result);
return result;
}
+ if (type == IContentOutlinePage.class) {
+ Object result = super.getAdapter(type);
+ if (result instanceof ContentOutlinePage) {
+ result = new OutlinePageWrapper((ContentOutlinePage) result);
+ }
+ return result;
+ }
return super.getAdapter(type);
}
@@ -266,7 +279,7 @@ public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor implem
* this command update the status of the toggle actions
*/
protected void updateToggleActionState() {
- final ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class);
+ final ICommandService commandService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class);
if (commandService != null) {
final IPreferenceStore wsPreferenceStore = ((DiagramGraphicalViewer) getDiagramGraphicalViewer()).getWorkspaceViewerPreferenceStore();
org.eclipse.core.commands.Command command = commandService.getCommand(CommandIds.VIEW_GRID_COMMAND);
@@ -540,4 +553,76 @@ public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor implem
}
+ /**
+ * A wrapper for the GMF-provided outline page that lets us clean up references to the model content leaked via the Outline View tool bar.
+ */
+ private class OutlinePageWrapper implements IPageBookViewPage, IContentOutlinePage {
+ private final ContentOutlinePage delegate;
+
+ OutlinePageWrapper(ContentOutlinePage delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ delegate.createControl(parent);
+ }
+
+ @Override
+ public void dispose() {
+ try {
+ // Remove the toolbar items that reference me and, through me, the diagram and its associated semantic model
+ IActionBars bars = getSite().getActionBars();
+ bars.getToolBarManager().removeAll();
+ bars.updateActionBars();
+ } finally {
+ delegate.dispose();
+ }
+ }
+
+ @Override
+ public Control getControl() {
+ return delegate.getControl();
+ }
+
+ @Override
+ public void setActionBars(IActionBars actionBars) {
+ delegate.setActionBars(actionBars);
+ }
+
+ @Override
+ public void setFocus() {
+ delegate.setFocus();
+ }
+
+ @Override
+ public void init(IPageSite site) throws PartInitException {
+ delegate.init(site);
+ }
+
+ @Override
+ public IPageSite getSite() {
+ return delegate.getSite();
+ }
+
+ @Override
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ delegate.addSelectionChangedListener(listener);
+ }
+
+ @Override
+ public ISelection getSelection() {
+ return delegate.getSelection();
+ }
+
+ @Override
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ delegate.removeSelectionChangedListener(listener);
+ }
+
+ @Override
+ public void setSelection(ISelection selection) {
+ delegate.setSelection(selection);
+ }
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java
index 3c06078c1ef..0e8b907ba4e 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerPageBookView.java
@@ -12,7 +12,8 @@
* Ansgar Radermacher (CEA) ansgar.radermacher@cea.fr - Added support for IGotoMarker
* Christian W. Damus (CEA) - bug 434635
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 431117
- * Christian W. Damus - bug 450536
+ * Christian W. Damus - bug 450536
+ * Christian W. Damus - bug 451683
*
*****************************************************************************/
@@ -128,4 +129,17 @@ public class ModelExplorerPageBookView extends MultiViewPageBookView implements
super.saveState(memento);
}
+
+ @Override
+ public void partClosed(IWorkbenchPart part) {
+ PageRec rec = getPageRec(part);
+ if ((rec != null) && (rec.page instanceof ModelExplorerPage)) {
+ ModelExplorerView explorer = (ModelExplorerView) ((ModelExplorerPage) rec.page).getViewer();
+
+ // Clear the explorer tree input to prompt the CNF to clear caches, promoting garbage collection
+ explorer.aboutToDispose();
+ }
+
+ super.partClosed(part);
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
index 5a31085bcf6..5012c5794f5 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
@@ -14,6 +14,7 @@
* Christian W. Damus (CEA) - bug 437217
* Christian W. Damus (CEA) - bug 441857
* Christian W. Damus - bug 450235
+ * Christian W. Damus - bug 451683
*
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer;
@@ -26,7 +27,6 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.commands.operations.IUndoContext;
@@ -110,13 +110,12 @@ import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.internal.navigator.NavigatorContentService;
-import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.navigator.CommonViewerSorter;
import org.eclipse.ui.navigator.IExtensionActivationListener;
import org.eclipse.ui.navigator.ILinkHelper;
+import org.eclipse.ui.navigator.INavigatorContentService;
import org.eclipse.ui.navigator.LinkHelperService;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.properties.IPropertySheetPage;
@@ -907,6 +906,22 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
}
/**
+ * Invoked internally to clear the common viewer's associate listener in order to promote garbage collection.
+ */
+ void aboutToDispose() {
+ final CommonViewer viewer = getCommonViewer();
+ if ((viewer.getTree() != null) && !viewer.getTree().isDisposed()) {
+ viewer.setInput(null);
+
+ // Kick the NavigatorContentService to clear the cache in its StructuredViewerManager that leaks all of our tree elements
+ INavigatorContentService contentService = getNavigatorContentService();
+ if (contentService instanceof IExtensionActivationListener) {
+ ((IExtensionActivationListener) getNavigatorContentService()).onExtensionActivation(contentService.getViewerId(), new String[0], false);
+ }
+ }
+ }
+
+ /**
* {@inheritDoc}
*/
@Override

Back to the top