Merge "Remove listeners on dispose to prevent memory leaks."
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexActionBarContributor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexActionBarContributor.java
index a1f7ab6..7e0a951 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexActionBarContributor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexActionBarContributor.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2013 John Krasnay 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
@@ -7,6 +7,7 @@
  * 
  * Contributors:
  *     John Krasnay - initial API and implementation
+ *     Carsten Hiesserich - remove selection listener on dispose (bug 413878)
  *******************************************************************************/
 package org.eclipse.vex.ui.internal.editor;
 
@@ -36,6 +37,8 @@
 
 	@Override
 	public void dispose() {
+		activeEditor = null;
+		getPage().removeSelectionListener(selectionListener);
 	}
 
 	public VexEditor getVexEditor() {
@@ -62,6 +65,7 @@
 		// This can occur if we have an error loading the editor,
 		// in which case Eclipse provides its own part
 		if (!(activeEditor instanceof VexEditor)) {
+			this.activeEditor = null;
 			return;
 		}
 
@@ -184,4 +188,4 @@
 		}
 	}
 
-}
+}
\ No newline at end of file
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
index 2ead86c..da725e0 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
@@ -9,6 +9,7 @@
  *     John Krasnay - initial API and implementation
  *     Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
  *     Carsten Hiesserich - added styleChanged event
+ *     Carsten Hiesserich - remove listeners on dispose (bug 413878)
  *******************************************************************************/
 package org.eclipse.vex.ui.internal.editor;
 
@@ -150,6 +151,12 @@
 	public void dispose() {
 		super.dispose();
 
+		if (document != null) {
+			document.removeDocumentListener(documentListener);
+		}
+
+		getEditorSite().getSelectionProvider().removeSelectionChangedListener(selectionChangedListener);
+
 		if (parentControl != null) {
 			// createPartControl was called, so we must de-register from config
 			// events