Index: /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1455)
+++ /trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 1456)
@@ -89,7 +89,11 @@
 //  (std: 3 sigma, clean level 1)
 //
-void MImgCleanStd::CleanStep1()
+//  Returns the maximum Pixel Id (used for ispixused in CleanStep2)
+//
+Int_t MImgCleanStd::CleanStep1()
 {
     const Int_t entries = fEvt->GetNumPixels();
+
+    Int_t max = entries;
 
     //
@@ -107,5 +111,9 @@
         if (entry <= fCleanLvl1 * noise)
             pix.SetPixelUnused();
-    }
+
+        if (pix.GetPixId()>max)
+            max = pix.GetPixId();
+    }
+    return max;
 }
 
@@ -115,5 +123,7 @@
 //  survived
 //
-void MImgCleanStd::CleanStep2()
+//  takes the maximum pixel id from CleanStep1 as an argument
+//
+void MImgCleanStd::CleanStep2(Int_t max)
 {
     const Int_t entries = fEvt->GetNumPixels();
@@ -125,8 +135,5 @@
     // (MCerPhotEvt::IsPixelUsed) all the time.
     //
-    // FIXME: The dynamic allocation may still be a problem if we
-    //        don't store all pixels in the array... but this music
-    //        of the future ;-)
-    Byte_t *ispixused = new Byte_t[fEvt->GetNumPixels()];
+    Byte_t *ispixused = new Byte_t[max];
 
     for (Int_t i=0; i<entries; i++)
