Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.cpp	(revision 57666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.cpp	(revision 57667)
@@ -112,4 +112,10 @@
     }
 
+    /* Cleanup all the tasks: */
+    qDeleteAll(m_pendingTasks);
+    qDeleteAll(m_executingTasks);
+    m_pendingTasks.clear();
+    m_executingTasks.clear();
+
     /* Unlock finally: */
     m_everythingLocker.unlock();
@@ -167,5 +173,5 @@
 
     /* Put the task into the queue: */
-    m_tasks.enqueue(pTask);
+    m_pendingTasks.enqueue(pTask);
 
     /* Wake up an idle worker if we got one: */
@@ -216,9 +222,12 @@
 
         /* Dequeue task if there is one: */
-        if (!m_tasks.isEmpty())
+        if (!m_pendingTasks.isEmpty())
         {
-            UITask *pTask = m_tasks.dequeue();
+            UITask *pTask = m_pendingTasks.dequeue();
             if (pTask)
             {
+                /* Put into the set of executing tasks: */
+                m_executingTasks << pTask;
+
                 /* Unlock finally: */
                 m_everythingLocker.unlock();
@@ -259,6 +268,17 @@
         return;
 
-    /* Notify listener: */
+    /* Notify listeners: */
     emit sigTaskComplete(pTask);
+
+    /* Lock initially: */
+    m_everythingLocker.lock();
+
+    /* Delete task finally: */
+    Assert(m_executingTasks.contains(pTask) &&
+           m_executingTasks.remove(pTask));
+    delete pTask;
+
+    /* Unlock finally: */
+    m_everythingLocker.unlock();
 }
 
@@ -296,5 +316,6 @@
     {
         /* Process the task if we are not terminating.
-         * Please take into account tasks are cleared by their creator. */
+         * Please take into account tasks are cleared by the UIThreadPool
+         * after all listeners notified about task is complete and handled it. */
         if (!m_pPool->isTerminating())
             pTask->start();
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h	(revision 57666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIThreadPool.h	(revision 57667)
@@ -23,4 +23,5 @@
 #include <QMutex>
 #include <QQueue>
+#include <QSet>
 #include <QVariant>
 #include <QVector>
@@ -92,7 +93,9 @@
     /** @name Task stuff
      * @{ */
-        /** Holds the queue (FIFO) of pending tasks. */
-        QQueue<UITask*> m_tasks;
-       /** Holds the condition variable that gets signalled when
+        /** Holds the queue of pending tasks. */
+        QQueue<UITask*> m_pendingTasks;
+        /** Holds the set of executing tasks. */
+        QSet<UITask*> m_executingTasks;
+        /** Holds the condition variable that gets signalled when
           * queuing a new task and there are idle worker threads around.
           * @remarks Idle threads sits in dequeueTask waiting for this.
Index: /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp	(revision 57666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp	(revision 57667)
@@ -84,11 +84,4 @@
     /* Listen for global thread-pool: */
     connect(vboxGlobal().threadPool(), SIGNAL(sigTaskComplete(UITask*)), this, SLOT(sltHandleMediumEnumerationTaskComplete(UITask*)));
-}
-
-UIMediumEnumerator::~UIMediumEnumerator()
-{
-    /* Delete all the tasks: */
-    while (!m_tasks.isEmpty())
-        delete m_tasks.takeFirst();
 }
 
@@ -276,6 +269,5 @@
     if (pTask->type() != UITask::Type_MediumEnumeration)
         return;
-    int iIndexOfTask = m_tasks.indexOf(pTask);
-    AssertReturnVoid(iIndexOfTask != -1);
+    AssertReturnVoid(m_tasks.contains(pTask));
 
     /* Get enumerated UIMedium: */
@@ -284,6 +276,6 @@
     LogRel2(("GUI: UIMediumEnumerator: Medium with key={%s} enumerated\n", strUIMediumKey.toAscii().constData()));
 
-    /* Delete task: */
-    delete m_tasks.takeAt(iIndexOfTask);
+    /* Remove task from internal set: */
+    m_tasks.remove(pTask);
 
     /* Make sure such UIMedium still exists: */
@@ -341,6 +333,6 @@
     /* Prepare medium-enumeration task: */
     UITask *pTask = new UITaskMediumEnumeration(medium);
-    /* Append to internal list: */
-    m_tasks.append(pTask);
+    /* Append to internal set: */
+    m_tasks << pTask;
     /* Post into global thread-pool: */
     vboxGlobal().threadPool()->enqueueTask(pTask);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h	(revision 57666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h	(revision 57667)
@@ -21,4 +21,5 @@
 /* Qt includes: */
 #include <QObject>
+#include <QSet>
 
 /* GUI includes: */
@@ -53,6 +54,4 @@
     /** Constructs medium-enumerator object. */
     UIMediumEnumerator();
-    /** Destructs medium-enumerator object. */
-    ~UIMediumEnumerator();
 
     /* API: Medium-access stuff: */
@@ -96,5 +95,5 @@
     /* Variables: */
     bool m_fMediumEnumerationInProgress;
-    QList<UITask*> m_tasks;
+    QSet<UITask*> m_tasks;
     UIMediumMap m_mediums;
 };
