Index: trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java	(revision 18685)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java	(revision 18686)
@@ -105,4 +105,30 @@
         } else {
             dlg.hideDialog();
+        }
+    }
+
+    /**
+     * Remove a {@link ToggleDialog} from the list of known dialogs and trigger reconstruct.
+     * @param toggleDialog The dialog to remove
+     * @since 18686
+     */
+    public void remove(ToggleDialog toggleDialog) {
+        remove(toggleDialog, true);
+    }
+
+    /**
+     * Remove a {@link ToggleDialog} from the list of known dialogs.
+     * @param toggleDialog The dialog to remove
+     * @param doReconstruct <code>true</code> if reconstruction should be triggered.
+     * @since 18686
+     */
+    public void remove(ToggleDialog toggleDialog, boolean doReconstruct) {
+        toggleDialog.setDialogsPanel(null);
+        final JPanel oldPanel = panels.get(allDialogs.indexOf(toggleDialog));
+        allDialogs.remove(toggleDialog);
+        panels.remove(oldPanel);
+        mSpltPane.remove(oldPanel);
+        if (doReconstruct && !allDialogs.isEmpty()) {
+            reconstruct(Action.ELEMENT_SHRINKS, toggleDialog);
         }
     }
@@ -326,5 +352,5 @@
     @Override
     public void destroy() {
-        for (ToggleDialog t : allDialogs) {
+        for (ToggleDialog t : new ArrayList<>(allDialogs)) {
             try {
                 t.destroy();
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 18685)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java	(revision 18686)
@@ -478,5 +478,8 @@
     @Override
     public void destroy() {
-        dialogsPanel = null;
+        if (dialogsPanel != null) {
+            dialogsPanel.remove(this);
+            dialogsPanel = null;
+        }
         rememberHeight();
         closeDetachedDialog();
Index: trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 18685)
+++ trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java	(revision 18686)
@@ -145,4 +145,10 @@
      */
     private static void destroyInstance() {
+        MapFrame map = MainApplication.getMap();
+        synchronized (ImageViewerDialog.class) {
+            if (dialog != null && map != null && map.getToggleDialog(ImageViewerDialog.class) != null) {
+                map.removeToggleDialog(dialog);
+            }
+        }
         dialog = null;
     }
