Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp	(revision 45452)
@@ -70,4 +70,40 @@
 #include <iprt/param.h>
 #include <iprt/path.h>
+
+/* static */
+UIMessageCenter* UIMessageCenter::m_spInstance = 0;
+UIMessageCenter* UIMessageCenter::instance() { return m_spInstance; }
+
+/* static */
+void UIMessageCenter::create()
+{
+    /* Make sure instance is NOT created yet: */
+    if (m_spInstance)
+    {
+        AssertMsgFailed(("UIMessageCenter instance is already created!"));
+        return;
+    }
+
+    /* Create instance: */
+    new UIMessageCenter;
+    /* Prepare instance: */
+    m_spInstance->prepare();
+}
+
+/* static */
+void UIMessageCenter::destroy()
+{
+    /* Make sure instance is NOT destroyed yet: */
+    if (!m_spInstance)
+    {
+        AssertMsgFailed(("UIMessageCenter instance is already destroyed!"));
+        return;
+    }
+
+    /* Cleanup instance: */
+    m_spInstance->cleanup();
+    /* Destroy instance: */
+    delete m_spInstance;
+}
 
 bool UIMessageCenter::warningShown(const QString &strWarningName) const
@@ -2534,4 +2570,16 @@
 UIMessageCenter::UIMessageCenter()
 {
+    /* Assign instance: */
+    m_spInstance = this;
+}
+
+UIMessageCenter::~UIMessageCenter()
+{
+    /* Unassign instance: */
+    m_spInstance = 0;
+}
+
+void UIMessageCenter::prepare()
+{
     /* Register required objects as meta-types: */
     qRegisterMetaType<CProgress>();
@@ -2570,9 +2618,7 @@
 }
 
-/* Returns a reference to the global VirtualBox message center instance: */
-UIMessageCenter &UIMessageCenter::instance()
-{
-    static UIMessageCenter global_instance;
-    return global_instance;
+void UIMessageCenter::cleanup()
+{
+     /* Nothing for now... */
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h	(revision 45452)
@@ -73,4 +73,8 @@
         AutoConfirmed = 0x8000
     };
+
+    /* Static API: Create/destroy stuff: */
+    static void create();
+    static void destroy();
 
     /* API: Warning registration stuff: */
@@ -383,10 +387,11 @@
 private:
 
-    /* Constructor: */
+    /* Constructor/destructor: */
     UIMessageCenter();
-
-    /* Instance stuff: */
-    static UIMessageCenter &instance();
-    friend UIMessageCenter &msgCenter();
+    ~UIMessageCenter();
+
+    /* Helpers: Prepare/cleanup stuff: */
+    void prepare();
+    void cleanup();
 
     /* Helper: */
@@ -402,8 +407,13 @@
     /* Variables: */
     mutable QStringList m_warnings;
+
+    /* API: Instance stuff: */
+    static UIMessageCenter* m_spInstance;
+    static UIMessageCenter* instance();
+    friend UIMessageCenter& msgCenter();
 };
 
-/* Shortcut to the static UIMessageCenter::instance() method, for convenience. */
-inline UIMessageCenter &msgCenter() { return UIMessageCenter::instance(); }
+/* Shortcut to the static UIMessageCenter::instance() method: */
+inline UIMessageCenter& msgCenter() { return *UIMessageCenter::instance(); }
 
 #endif // __UIMessageCenter_h__
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.cpp	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.cpp	(revision 45452)
@@ -29,13 +29,16 @@
 
 /* static */
+UIModalWindowManager* UIModalWindowManager::m_spInstance = 0;
 UIModalWindowManager* UIModalWindowManager::instance() { return m_spInstance; }
-UIModalWindowManager* UIModalWindowManager::m_spInstance = 0;
 
 /* static */
 void UIModalWindowManager::create()
 {
-    /* Make sure instance is not created: */
+    /* Make sure instance is NOT created yet: */
     if (m_spInstance)
-        return;
+    {
+        AssertMsgFailed(("UIModalWindowManager instance is already created!"));
+        return;
+    }
 
     /* Create instance: */
@@ -46,9 +49,12 @@
 void UIModalWindowManager::destroy()
 {
-    /* Make sure instance is created: */
+    /* Make sure instance is NOT destroyed yet: */
     if (!m_spInstance)
-        return;
-
-    /* Create instance: */
+    {
+        AssertMsgFailed(("UIModalWindowManager instance is already destroyed!"));
+        return;
+    }
+
+    /* Destroy instance: */
     delete m_spInstance;
 }
@@ -56,26 +62,20 @@
 UIModalWindowManager::UIModalWindowManager()
 {
-    /* Make sure instance is not assigned: */
-    if (m_spInstance != this)
-        m_spInstance = this;
+    /* Assign instance: */
+    m_spInstance = this;
 }
 
 UIModalWindowManager::~UIModalWindowManager()
 {
-    /* Make sure instance still assigned: */
-    if (m_spInstance == this)
-        m_spInstance = 0;
+    /* Unassign instance: */
+    m_spInstance = 0;
 }
 
 QWidget* UIModalWindowManager::mainWindowShown() const
 {
-    /* Later this function will be independent of VBoxGlobal at all,
-     * but for now VBoxGlobal creates all the main application windows,
-     * so we should honor this fact.
-     *
-     * It may happen that this method is called during VBoxGlobal
-     * initialization or even after it had failed (for example, to show some message).
-     * Return NULL pointer in this case: */
-    if (!vboxGlobal().isValid())
+    /* It may happen that this method is called before VBoxGlobal initialization
+     * or after initialization had failed (for example, to show some message).
+     * Return NULL pointer in such cases: */
+    if (!VBoxGlobal::instance() || !vboxGlobal().isValid())
         return 0;
 
@@ -88,5 +88,5 @@
             return vboxGlobal().activeMachineWindow();
     }
-    /* Otherwise: */
+    /* For VM selector process: */
     else
     {
@@ -96,5 +96,5 @@
     }
 
-    /* Nothing by default: */
+    /* NULL by default: */
     return 0;
 }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.h	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.h	(revision 45452)
@@ -2,5 +2,5 @@
  *
  * VBox frontends: Qt GUI ("VirtualBox"):
- * UIModalWindowManager class definition
+ * UIModalWindowManager class declaration
  */
 
@@ -66,7 +66,7 @@
     /* Variables: */
     QList<QList<QWidget*> > m_windows;
-    static UIModalWindowManager* m_spInstance;
 
     /* Static API: Instance stuff: */
+    static UIModalWindowManager* m_spInstance;
     static UIModalWindowManager* instance();
     friend UIModalWindowManager& windowManager();
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp	(revision 45452)
@@ -32,7 +32,7 @@
 
 /* static */
-void UIPopupCenter::prepare()
+void UIPopupCenter::create()
 {
-    /* Make sure instance is not created yet: */
+    /* Make sure instance is NOT created yet: */
     if (m_spInstance)
         return;
@@ -43,11 +43,11 @@
 
 /* static */
-void UIPopupCenter::cleanup()
+void UIPopupCenter::destroy()
 {
-    /* Make sure instance is still created: */
+    /* Make sure instance is NOT destroyed yet: */
     if (!m_spInstance)
         return;
 
-    /* Create instance: */
+    /* Destroy instance: */
     delete m_spInstance;
 }
@@ -55,14 +55,12 @@
 UIPopupCenter::UIPopupCenter()
 {
-    /* Prepare instance: */
-    if (!m_spInstance)
-        m_spInstance = this;
+    /* Assign instance: */
+    m_spInstance = this;
 }
 
 UIPopupCenter::~UIPopupCenter()
 {
-    /* Cleanup instance: */
-    if (m_spInstance)
-        m_spInstance = 0;
+    /* Unassign instance: */
+    m_spInstance = 0;
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h	(revision 45452)
@@ -32,7 +32,7 @@
 public:
 
-    /* Prepare/cleanup stuff: */
-    static void prepare();
-    static void cleanup();
+    /* Static API: Create/destroy stuff: */
+    static void create();
+    static void destroy();
 
     /* API: Main message function, used directly only in exceptional cases: */
@@ -90,8 +90,4 @@
     ~UIPopupCenter();
 
-    /* Instance stuff: */
-    static UIPopupCenter* instance();
-    friend UIPopupCenter& popupCenter();
-
     /* Helper: Popup-box stuff: */
     void showPopupBox(QWidget *pParent,
@@ -102,9 +98,13 @@
 
     /* Variables: */
+    mutable QMap<QString, QPointer<QWidget> > m_popups;
+
+    /* Instance stuff: */
     static UIPopupCenter* m_spInstance;
-    mutable QMap<QString, QPointer<QWidget> > m_popups;
+    static UIPopupCenter* instance();
+    friend UIPopupCenter& popupCenter();
 };
 
-/* Shortcut to the static UIPopupCenter::instance() method, for convenience: */
+/* Shortcut to the static UIPopupCenter::instance() method: */
 inline UIPopupCenter& popupCenter() { return *UIPopupCenter::instance(); }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 45452)
@@ -186,21 +186,4 @@
 // VBoxGlobal
 ////////////////////////////////////////////////////////////////////////////////
-
-static bool sVBoxGlobalInited = false;
-static bool sVBoxGlobalInCleanup = false;
-
-/** @internal
- *
- *  Special routine to do VBoxGlobal cleanup when the application is being
- *  terminated. It is called before some essential Qt functionality (for
- *  instance, QThread) becomes unavailable, allowing us to use it from
- *  VBoxGlobal::cleanup() if necessary.
- */
-static void vboxGlobalCleanup()
-{
-    Assert (!sVBoxGlobalInCleanup);
-    sVBoxGlobalInCleanup = true;
-    vboxGlobal().cleanup();
-}
 
 /** @internal
@@ -258,12 +241,40 @@
 }
 
-/** @class VBoxGlobal
- *
- *  The VBoxGlobal class encapsulates the global VirtualBox data.
- *
- *  There is only one instance of this class per VirtualBox application,
- *  the reference to it is returned by the static instance() method, or by
- *  the global vboxGlobal() function, that is just an inlined shortcut.
- */
+/* static */
+bool VBoxGlobal::m_sfCleanupInProgress = false;
+VBoxGlobal* VBoxGlobal::m_spInstance = 0;
+VBoxGlobal* VBoxGlobal::instance() { return m_spInstance; }
+
+/* static */
+void VBoxGlobal::create()
+{
+    /* Make sure instance is NOT created yet: */
+    if (m_spInstance)
+    {
+        AssertMsgFailed(("VBoxGlobal instance is already created!"));
+        return;
+    }
+
+    /* Create instance: */
+    new VBoxGlobal;
+    /* Prepare instance: */
+    m_spInstance->prepare();
+}
+
+/* static */
+void VBoxGlobal::destroy()
+{
+    /* Make sure instance is NOT destroyed yet: */
+    if (!m_spInstance)
+    {
+        AssertMsgFailed(("VBoxGlobal instance is already destroyed!"));
+        return;
+    }
+
+    /* Cleanup instance: */
+    /* Automatically on QApplication::aboutToQuit() signal: */
+    /* Destroy instance: */
+    delete m_spInstance;
+}
 
 VBoxGlobal::VBoxGlobal()
@@ -282,61 +293,12 @@
     , mSettingsPwSet(false)
 {
-}
-
-//
-// Public members
-/////////////////////////////////////////////////////////////////////////////
-
-/**
- *  Returns a reference to the global VirtualBox data, managed by this class.
- *
- *  The main() function of the VBox GUI must call this function soon after
- *  creating a QApplication instance but before opening any of the main windows
- *  (to let the VBoxGlobal initialization procedure use various Qt facilities),
- *  and continue execution only when the isValid() method of the returned
- *  instancereturns true, i.e. do something like:
- *
- *  @code
- *  if ( !VBoxGlobal::instance().isValid() )
- *      return 1;
- *  @endcode
- *  or
- *  @code
- *  if ( !vboxGlobal().isValid() )
- *      return 1;
- *  @endcode
- *
- *  @note Some VBoxGlobal methods can be used on a partially constructed
- *  VBoxGlobal instance, i.e. from constructors and methods called
- *  from the VBoxGlobal::init() method, which obtain the instance
- *  using this instance() call or the ::vboxGlobal() function. Currently, such
- *  methods are:
- *      #vmStateText, #vmTypeIcon, #vmTypeText, #vmTypeTextList, #vmTypeFromText.
- *
- *  @see ::vboxGlobal
- */
-VBoxGlobal &VBoxGlobal::instance()
-{
-    static VBoxGlobal vboxGlobal_instance;
-
-    if (!sVBoxGlobalInited)
-    {
-        /* check that a QApplication instance is created */
-        if (qApp)
-        {
-            sVBoxGlobalInited = true;
-            vboxGlobal_instance.init();
-            /* add our cleanup handler to the list of Qt post routines */
-            qAddPostRoutine (vboxGlobalCleanup);
-        }
-        else
-            AssertMsgFailed (("Must construct a QApplication first!"));
-    }
-    return vboxGlobal_instance;
+    /* Assign instance: */
+    m_spInstance = this;
 }
 
 VBoxGlobal::~VBoxGlobal()
 {
-    qDeleteAll (mOsTypeIcons);
+    /* Unassign instance: */
+    m_spInstance = 0;
 }
 
@@ -1780,6 +1742,6 @@
         return;
 
-    /* ignore the request during application termination */
-    if (sVBoxGlobalInCleanup)
+    /* Ignore the request during VBoxGlobal cleanup: */
+    if (m_sfCleanupInProgress)
         return;
 
@@ -1817,5 +1779,5 @@
 
             /* Enumerate the list */
-            for (int i = 0; i < mVector.size() && !sVBoxGlobalInCleanup; ++ i)
+            for (int i = 0; i < mVector.size() && !m_sfCleanupInProgress; ++ i)
             {
                 mVector [i].blockAndQueryState();
@@ -1827,5 +1789,5 @@
 
             /* Post the end-of-enumeration event */
-            if (!sVBoxGlobalInCleanup)
+            if (!m_sfCleanupInProgress)
                 QApplication::postEvent (self, new VBoxMediaEnumEvent (mSavedIt));
 
@@ -4019,8 +3981,16 @@
 }
 
-void VBoxGlobal::init()
-{
+void VBoxGlobal::prepare()
+{
+    /* Make sure QApplication cleanup us on exit: */
+    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanup()));
+
+    /* Create message-center: */
+    UIMessageCenter::create();
     /* Create popup-center: */
-    UIPopupCenter::prepare();
+    UIPopupCenter::create();
+
+    /* Load translation based on the current locale: */
+    loadLanguage();
 
 #ifdef DEBUG
@@ -4068,6 +4038,5 @@
     }
 
-    /* Load the customized language as early as possible to get possible error
-     * messages translated */
+    /* Load translation based on the user settings: */
     QString sLanguageId = gset.languageId();
     if (!sLanguageId.isNull())
@@ -4460,12 +4429,10 @@
 }
 
-
-/** @internal
- *
- *  This method should be never called directly. It is called automatically
- *  when the application terminates.
- */
 void VBoxGlobal::cleanup()
 {
+    /* Preventing some unwanted stuff
+     * which could de called from the other threads: */
+    m_sfCleanupInProgress = true;
+
     /* Shutdown update manager: */
     UIUpdateManager::shutdown();
@@ -4479,11 +4446,4 @@
     /* Destroy shortcut pool: */
     UIShortcutPool::destroy();
-
-    /* sanity check */
-    if (!sVBoxGlobalInCleanup)
-    {
-        AssertMsgFailed (("Should never be called directly\n"));
-        return;
-    }
 
 #ifdef VBOX_GUI_WITH_PIDFILE
@@ -4497,5 +4457,4 @@
     if (mMediaEnumThread)
     {
-        /* sVBoxGlobalInCleanup is true here, so just wait for the thread */
         mMediaEnumThread->wait();
         delete mMediaEnumThread;
@@ -4509,4 +4468,7 @@
 
     UIConverter::cleanup();
+
+    /* Ensure mOsTypeIcons is cleaned up: */
+    qDeleteAll(mOsTypeIcons);
 
     /* ensure CGuestOSType objects are no longer used */
@@ -4528,5 +4490,7 @@
 
     /* Destroy popup-center: */
-    UIPopupCenter::cleanup();
+    UIPopupCenter::destroy();
+    /* Destroy message-center: */
+    UIMessageCenter::destroy();
 
     mValid = false;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 45452)
@@ -64,5 +64,8 @@
 public:
 
-    static VBoxGlobal &instance();
+    /* Static API: Create/destroy stuff: */
+    static VBoxGlobal* instance();
+    static void create();
+    static void destroy();
 
     bool isValid() { return mValid; }
@@ -284,7 +287,4 @@
     void retranslateUi();
 
-    /** @internal made public for internal purposes */
-    void cleanup();
-
     /* public static stuff */
 
@@ -422,4 +422,10 @@
     void sltProcessGlobalSettingChange();
 
+protected slots:
+
+    /* Handlers: Prepare/cleanup stuff: */
+    void prepare();
+    void cleanup();
+
 protected:
 
@@ -429,8 +435,8 @@
 private:
 
+    /* Constructor/destructor: */
     VBoxGlobal();
     ~VBoxGlobal();
 
-    void init();
 #ifdef VBOX_WITH_DEBUGGER_GUI
     void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false);
@@ -522,8 +528,12 @@
     bool mSettingsPwSet;
 
-    friend VBoxGlobal &vboxGlobal();
+    /* API: Instance stuff: */
+    static bool m_sfCleanupInProgress;
+    static VBoxGlobal* m_spInstance;
+    friend VBoxGlobal& vboxGlobal();
 };
 
-inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); }
+/* Shortcut to the static VBoxGlobal::instance() method: */
+inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); }
 
 #endif /* __VBoxGlobal_h__ */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/main.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/main.cpp	(revision 45451)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/main.cpp	(revision 45452)
@@ -412,9 +412,9 @@
         bool isCurrentScaleable = fontDataBase.isScalable(currentFamily);
 
-        QString subFamily (QFont::substitute (currentFamily));
-        bool isSubScaleable = fontDataBase.isScalable (subFamily);
+        QString subFamily(QFont::substitute(currentFamily));
+        bool isSubScaleable = fontDataBase.isScalable(subFamily);
 
         if (isCurrentScaleable && !isSubScaleable)
-            QFont::removeSubstitution (currentFamily);
+            QFont::removeSubstitution(currentFamily);
 # endif /* Q_OS_SOLARIS */
 #endif /* Q_WS_X11 */
@@ -446,4 +446,5 @@
                                   strMsg, QMessageBox::Abort, 0);
             qFatal("%s", strMsg.toAscii().constData());
+            break;
         }
 #endif /* Q_WS_X11 */
@@ -452,6 +453,6 @@
         UIModalWindowManager::create();
 
-        /* Load a translation based on the current locale: */
-        VBoxGlobal::loadLanguage();
+        /* Create global UI instance: */
+        VBoxGlobal::create();
 
         /* Simulate try-catch block: */
@@ -519,4 +520,7 @@
         while (0);
 
+        /* Destroy global UI instance: */
+        VBoxGlobal::destroy();
+
         /* Destroy modal-window manager: */
         UIModalWindowManager::destroy();
