Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 60435)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 60436)
@@ -4352,7 +4352,8 @@
     mValid = true;
 
+    /* Prepare converter: */
     UIConverter::prepare();
 
-    /* Create medium enumerator but don't do any immediate caching. */
+    /* Create medium-enumerator but don't do any immediate caching: */
     m_pMediumEnumerator = new UIMediumEnumerator;
     {
@@ -4389,6 +4390,7 @@
 void VBoxGlobal::cleanup()
 {
-    /* Preventing some unwanted stuff
-     * which could de called from the other threads: */
+    // TODO: Shouldn't that be protected with a mutex or something?
+    /* Remember that the cleanup is in progress preventing any unwanted
+     * stuff which could be called from the other threads: */
     m_sfCleanupInProgress = true;
 
@@ -4406,28 +4408,32 @@
 #ifdef VBOX_GUI_WITH_PIDFILE
     deletePidfile();
-#endif
-
-    /* Destroy the GUI root windows _BEFORE_ the media-mess, because there is
-       code in the GUI that's using the media code an will be racing us! */
+#endif /* VBOX_GUI_WITH_PIDFILE */
+
+    /* Destroy the GUI root windows _BEFORE_
+     * the media related code which could race us: */
     if (gpSelectorWindow)
         UISelectorWindow::destroy();
     if (gpMachine)
         UIMachine::destroy();
-    /* As part of recent change UIVirtualBoxEventHandler also used in runtimeUI.
-     * This needs to be destroyed before COM cleanup. As this is supposed to be only part of selectorUI,
-     * and needs to be reworked later doing this here for now: */
-    if (gpMachine)
-        UIVirtualBoxEventHandler::destroy();
-
-    /* Cleanup medium-enumerator: */
+
+    /* Starting medium-enumerator cleanup: */
     m_mediumEnumeratorDtorRwLock.lockForWrite();
-    delete m_pMediumEnumerator;
-    m_pMediumEnumerator = 0;
+    {
+        /* Destroy medium-enumerator: */
+        delete m_pMediumEnumerator;
+        m_pMediumEnumerator = 0;
+    }
+    /* Finishing medium-enumerator cleanup: */
     m_mediumEnumeratorDtorRwLock.unlock();
 
-    /* Destroy extra-data manager: */
+    /* Destroy the global (VirtualBox) Main event handler
+     * which is used in both Selector and Runtime UI. */
+    UIVirtualBoxEventHandler::destroy();
+
+    /* Destroy the extra-data manager finally after everything
+     * above which could use it already destroyed: */
     UIExtraDataManager::destroy();
 
-    /* Destroy whatever this converter stuff is: */
+    /* Cleanup converter: */
     UIConverter::cleanup();
 
@@ -4439,5 +4445,5 @@
     m_pIconPool = 0;
 
-    /* ensure CGuestOSType objects are no longer used */
+    /* Ensure CGuestOSType objects are no longer used: */
     m_guestOSFamilyIDs.clear();
     m_guestOSTypes.clear();
