Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 5620)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 5692)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2005
 !
 !
@@ -116,4 +116,8 @@
 using namespace std;
 
+#undef DEBUG
+//#define DEBUG
+
+
 // root 3.02:
 // check for TObjectWarning, TObject::Info, gErrorIgnoreLevel
@@ -216,5 +220,22 @@
     DeallocateFile();
 
+#ifdef DEBUG
+    TIter Next(fPlugins);
+    TObject *o=0;
+    while ((o=Next()))
+    {
+        cout << "Delete: " << o->GetName() << std::flush;
+        cout << " [" << o->ClassName() << "]" << endl;
+        delete o;
+    }
+
+    cout << "Delete: fPlugins " << fPlugins << "..." << std::flush;
+#endif
+
     delete fPlugins;
+#ifdef DEBUG
+    cout << "done." << endl;
+#endif
+
 #ifdef _REENTRANT
     delete fMuxStream;
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 5620)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 5692)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2005
 !
 !
@@ -109,5 +109,21 @@
 {
 #ifdef DEBUG
+    if (fName.IsNull() || fName==(TString)"MTime")
+        return;
+
     *fLog << all << "Deleting " << GetDescriptor() << endl;
+    if (TestBit(kMustCleanup) && gROOT && gROOT->MustClean())
+    {
+        *fLog << "Recursive Remove..." << flush;
+        if (TestBit(kCanDelete))
+            *fLog << "kCanDelete..." << flush;
+        TIter Next(gROOT->GetListOfCleanups());
+        TObject *o=0;
+        while ((o=Next()))
+            *fLog << dbg << o->GetName() << " [" << o->ClassName() << "]" << endl;
+        *fLog << dbg << "Removing..." << flush;
+        gROOT->GetListOfCleanups()->RecursiveRemove(this);
+        *fLog << "Removed." << endl;
+    }
 #endif
 }
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 5620)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 5692)
@@ -879,2 +879,51 @@
 
 }
+
+// --------------------------------------------------------------------------
+//
+//  Find an object with the same name in the list and replace it with
+//  the new one. If the kIsOwner flag is set and the object was not
+//  created automatically, the object is deleted.
+//
+Bool_t MTaskList::Replace(MTask *task)
+{
+    //
+    //  check if the object (you want to add) exists
+    //
+    if (!task)
+        return kFALSE;
+
+    if (task==this)
+    {
+        *fLog << warn << "WARNING - You cannot add a tasklist to itself.  This" << endl;
+        *fLog << "          would create infinite recursions...ignored." << endl;
+        return kFALSE;
+
+    }
+
+    MTask *obj = (MTask*)FindObject(task->GetName());
+    if (!obj)
+    {
+        *fLog << warn << "No object with the same name '";
+        *fLog << task->GetName() << "' in list... adding." << endl;
+        return AddToList(task);
+    }
+
+    if (task==obj)
+        return kTRUE;
+
+    *fLog << inf << "Adding " << task->GetName() << " to " << GetName() << " for " << obj->GetStreamId() << "... " << flush;
+    task->SetStreamId(obj->GetStreamId());
+    task->SetBit(kMustCleanup);
+    fTasks->AddAfter((TObject*)obj, task);
+    *fLog << "Done." << endl;
+
+    RemoveFromList(obj);
+
+    if (TestBit(kIsOwner))
+        delete obj;
+
+    //*fLog << inf << "MTask '" << task->GetName() << "' found and replaced..." << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 5620)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 5692)
@@ -49,4 +49,5 @@
     void SetSerialNumber(Byte_t num);
 
+    Bool_t Replace(MTask *obj);
     Bool_t RemoveFromList(MTask *task);
 
