From 278329357db66529136a29771cee0404990558c7 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Thu, 10 Jan 2013 19:29:16 +0100 Subject: [397904] Memory leaks in Juno when opening and closing XML Editor --- .../eclipse/wst/sse/ui/StructuredTextEditor.java | 25 +++++++++-- .../StructuredContentAssistProcessor.java | 2 +- .../wst/sse/ui/internal/StructuredTextViewer.java | 10 ++++- .../CompoundContentAssistProcessor.java | 3 +- .../contentassist/StructuredContentAssistant.java | 1 + .../propertytester/CustomFilterPropertyTester.java | 5 ++- .../internal/tabletree/XMLMultiPageEditorPart.java | 48 +++++++++++----------- .../XMLTableTreeActionBarContributor.java | 14 ++++--- .../eclipse/wst/xml/ui/internal/DOMObserver.java | 13 +++++- 9 files changed, 83 insertions(+), 38 deletions(-) diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java index f92cbbc9e3..490cf0ee86 100644 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java +++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2012 IBM Corporation and others. + * Copyright (c) 2001, 2013 IBM Corporation 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 @@ -105,6 +105,8 @@ import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.VerifyKeyListener; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; @@ -1112,7 +1114,7 @@ public class StructuredTextEditor extends TextEditor { private boolean fSelectionChangedFromGoto = false; - private final CharacterPairListener fPairInserter = new CharacterPairListener(); + private CharacterPairListener fPairInserter = new CharacterPairListener(); /** * Creates a new Structured Text Editor. @@ -1759,6 +1761,7 @@ public class StructuredTextEditor extends TextEditor { } if (fRulerContextMenu != null) { fRulerContextMenu.dispose(); + fRulerContextMenu = null; } if (fTextContextMenuManager != null) { fTextContextMenuManager.removeMenuListener(getContextMenuListener()); @@ -1802,6 +1805,7 @@ public class StructuredTextEditor extends TextEditor { if (fOutlinePageListener != null) { fOutlinePage.removeSelectionChangedListener(fOutlinePageListener); } + fOutlinePage = null; } fEditorDisposed = true; @@ -1817,8 +1821,9 @@ public class StructuredTextEditor extends TextEditor { uninstallSemanticHighlighting(); - if (fPairInserter != null) + if (fPairInserter != null) { fPairInserter.dispose(); + } setPreferenceStore(null); @@ -1834,6 +1839,10 @@ public class StructuredTextEditor extends TextEditor { if (fStructuredSelectionProvider != null) { fStructuredSelectionProvider.dispose(); } + + if (fStatusLineLabelProvider != null) { + fStatusLineLabelProvider.dispose(); + } setStatusLineMessage(null); @@ -2083,7 +2092,7 @@ public class StructuredTextEditor extends TextEditor { } // content outline page else if (IContentOutlinePage.class.equals(required)) { - if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) { + if (fOutlinePage == null) { ContentOutlineConfiguration cfg = createContentOutlineConfiguration(); if (cfg != null) { ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage(); @@ -2637,6 +2646,14 @@ public class StructuredTextEditor extends TextEditor { fDropAdapter.setTextViewer(textViewer); fDropTarget.setTransfer(fDropAdapter.getTransfers()); fDropTarget.addDropListener(fDropAdapter); + fDropTarget.addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + fDropTarget.removeDropListener(fDropAdapter); + fDropTarget.removeDisposeListener(this); + fDropTarget.dispose(); + } + }); } /* diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/contentassist/StructuredContentAssistProcessor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/contentassist/StructuredContentAssistProcessor.java index 78efc28069..a2ad1692ad 100644 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/contentassist/StructuredContentAssistProcessor.java +++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/contentassist/StructuredContentAssistProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 IBM Corporation and others. + * Copyright (c) 2010, 2013 IBM Corporation 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 diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java index f7e3650e66..198fac2b92 100644 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java +++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2010 IBM Corporation and others. + * Copyright (c) 2001, 2013 IBM Corporation 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 @@ -715,6 +715,14 @@ public class StructuredTextViewer extends ProjectionViewer implements IDocumentS fRecHighlighter.uninstall(); fRecHighlighter = null; } + if (fContentAssistant != null) { + fContentAssistant.uninstall(); + if (fContentAssistantFacade != null) { + fContentAssistantFacade= null; + } + fContentAssistantInstalled = false; + fContentAssistant = null; + } super.handleDispose(); Logger.trace("Source Editor", "StructuredTextViewer::handleDispose exit"); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java index 7e89b4395e..f76003e097 100644 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java +++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2013 IBM Corporation 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 @@ -375,6 +375,7 @@ public class CompoundContentAssistProcessor implements IContentAssistProcessor, ((IReleasable) p).release(); } } + fProcessors.clear(); } private static class WrappedContextInformation implements IContextInformation, IContextInformationExtension { diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java index 8d124cebd9..53e9d51292 100644 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java +++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java @@ -119,6 +119,7 @@ public class StructuredContentAssistant extends ContentAssistant { } } fProcessorsReleased = true; + this.fReleasableProcessors.clear(); super.uninstall(); } } \ No newline at end of file diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/propertytester/CustomFilterPropertyTester.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/propertytester/CustomFilterPropertyTester.java index e4fa4d7f0f..d1cd362423 100644 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/propertytester/CustomFilterPropertyTester.java +++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/propertytester/CustomFilterPropertyTester.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 IBM Corporation and others. + * Copyright (c) 2011, 2013 IBM Corporation 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 @@ -24,7 +24,8 @@ public class CustomFilterPropertyTester extends PropertyTester { */ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver instanceof IEditorPart){ - return ((IEditorPart) receiver).getAdapter(IContentOutlinePage.class) instanceof ConfigurableContentOutlinePage; + IContentOutlinePage outlinePage = (IContentOutlinePage) ((IEditorPart) receiver).getAdapter(IContentOutlinePage.class); + return (outlinePage instanceof ConfigurableContentOutlinePage && outlinePage.getControl() != null && !outlinePage.getControl().isDisposed()); } return false; } diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java index 014eb754f1..5e8c942cdd 100644 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java +++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2004, 2012 IBM Corporation and others. All rights reserved. This + * Copyright (c) 2004, 2013 IBM Corporation 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 http://www.eclipse.org/legal/epl-v10.html @@ -74,8 +74,6 @@ import org.eclipse.ui.part.MultiPageEditorSite; import org.eclipse.ui.part.MultiPageSelectionProvider; import org.eclipse.ui.progress.UIJob; import org.eclipse.ui.texteditor.IDocumentProvider; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.TextSelectionNavigationLocation; import org.eclipse.wst.sse.core.StructuredModelManager; import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; @@ -491,6 +489,8 @@ public class XMLMultiPageEditorPart extends MultiPageEditorPart implements INavi private MenuManager fMenuManager; private boolean fAllocateToolbar = true; + + private TextInputListener fTextInputListener; /** * StructuredTextMultiPageEditorPart constructor comment. @@ -520,7 +520,8 @@ public class XMLMultiPageEditorPart extends MultiPageEditorPart implements INavi // Changes to the Text Viewer's document instance should also // force an // input refresh - fTextEditor.getTextViewer().addTextInputListener(new TextInputListener()); + fTextInputListener = new TextInputListener(); + fTextEditor.getTextViewer().addTextInputListener(fTextInputListener); } /** @@ -861,7 +862,12 @@ public class XMLMultiPageEditorPart extends MultiPageEditorPart implements INavi public void dispose() { Logger.trace("Source Editor", "XMLMultiPageEditorPart::dispose entry"); //$NON-NLS-1$ //$NON-NLS-2$ + if (fTextInputListener != null) { + fTextEditor.getTextViewer().removeTextInputListener(fTextInputListener); + fTextInputListener = null; + } disconnectDesignPage(); + fDesignViewer = null; if (fActivationListener != null) { fActivationListener.dispose(); @@ -874,15 +880,27 @@ public class XMLMultiPageEditorPart extends MultiPageEditorPart implements INavi fMenuManager = null; } - if ((fTextEditor != null) && (fPropertyListener != null)) { + if (fPropertyListener != null) { fTextEditor.removePropertyListener(fPropertyListener); + fPropertyListener = null; } + if (fEditorManager != null) { + fEditorManager.dispose(); + fEditorManager = null; + } + if (fToolbarManager != null) { + fToolbarManager.dispose(); + fToolbarManager = null; + } // moved to last when added window ... seems like // we'd be in danger of losing some data, like site, // or something. super.dispose(); + fTextEditor = null; + fPageInitializer = null; + Logger.trace("Source Editor", "StructuredTextMultiPageEditorPart::dispose exit"); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -1136,15 +1154,7 @@ public class XMLMultiPageEditorPart extends MultiPageEditorPart implements INavi return new DesignPageNavigationLocation(this, fDesignViewer, false); } // Makes sure that the text editor is returned - return new TextSelectionNavigationLocation(fTextEditor, false) { - protected IEditorPart getEditorPart() { - IEditorPart part = super.getEditorPart(); - if (part != null) { - part = (ITextEditor) part.getAdapter(ITextEditor.class); - } - return part; - } - }; + return fTextEditor.createEmptyNavigationLocation(); } public INavigationLocation createNavigationLocation() { @@ -1152,15 +1162,7 @@ public class XMLMultiPageEditorPart extends MultiPageEditorPart implements INavi return new DesignPageNavigationLocation(this, fDesignViewer, true); } // Makes sure that the text editor is returned - return new TextSelectionNavigationLocation(fTextEditor, true) { - protected IEditorPart getEditorPart() { - IEditorPart part = super.getEditorPart(); - if (part != null) { - part = (ITextEditor) part.getAdapter(ITextEditor.class); - } - return part; - } - }; + return fTextEditor.createNavigationLocation(); } public void saveState(IMemento memento) { diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java index 4af5032074..10a57075a5 100644 --- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java +++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation 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 @@ -54,6 +54,7 @@ public class XMLTableTreeActionBarContributor implements IDesignViewerActionBarC protected ViewerExpandCollapseAction collapseAction; protected ViewerExpandCollapseAction xmlMenuExpandAction; protected ViewerExpandCollapseAction xmlMenuCollapseAction; + private IActionBars actionBars; public XMLTableTreeActionBarContributor() { } @@ -88,6 +89,7 @@ public class XMLTableTreeActionBarContributor implements IDesignViewerActionBarC } public void init(IActionBars bars) { + this.actionBars = bars; // IToolBarManager tbm = bars.getToolBarManager(); /* IMenuManager xmlMenu = bars.getMenuManager().findMenuUsingPath("org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ @@ -184,15 +186,16 @@ public class XMLTableTreeActionBarContributor implements IDesignViewerActionBarC xmlMenuCollapseAction.setViewer(tableTreeViewer); } */ + ITextEditor textEditor = null; if (editorPart instanceof XMLMultiPageEditorPart) { IWorkbenchPartSite site = editorPart.getSite(); if (site instanceof IEditorSite) { - ITextEditor textEditor = ((XMLMultiPageEditorPart) editorPart).getTextEditor(); - IActionBars actionBars = ((IEditorSite) site).getActionBars(); - actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO)); - actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO)); + textEditor = ((XMLMultiPageEditorPart) editorPart).getTextEditor(); } } + actionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO)); + actionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO)); + // TODO... uncomment this and investigate NPE // @@ -317,5 +320,6 @@ public class XMLTableTreeActionBarContributor implements IDesignViewerActionBarC * @see org.eclipse.ui.IEditorActionBarContributor#dispose() */ public void dispose() { + setActiveEditor(null); } } diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java index 4b90cfb3ff..1cb7f23a28 100644 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java +++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/DOMObserver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2009 IBM Corporation and others. + * Copyright (c) 2001, 2013 IBM Corporation 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,9 @@ package org.eclipse.wst.xml.ui.internal; +import java.util.Collection; +import java.util.Iterator; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -164,6 +167,14 @@ public class DOMObserver { if (fDocument != null) { // here we create and init an adapter that will listen to // changes to the document and contained elements + Collection adapters = ((INodeNotifier) fDocument).getAdapters(); + Iterator iterator = adapters.iterator(); + while (iterator.hasNext()) { + INodeAdapter adapter = (INodeAdapter) iterator.next(); + if (adapter instanceof MyDocumentAdapter) { + return; + } + } MyDocumentAdapter adapter = new MyDocumentAdapter(); adapter.connect(fDocument); -- cgit v1.2.3