Index: trunk/ppStack/src/ppStackLoop.c
===================================================================
--- trunk/ppStack/src/ppStackLoop.c	(revision 18391)
+++ trunk/ppStack/src/ppStackLoop.c	(revision 18393)
@@ -30,4 +30,33 @@
                              "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID",
                              "PSPHOT.INPUT.CMF", NULL };
+
+static void memDump(const char *name)
+{
+    return;
+
+    static int num = 0;                 // Counter, to make files unique and give an idea of sequence
+
+    psString filename = NULL;           // Name of file
+    psStringAppend(&filename, "memdump_%s_%03d.txt", name, num);
+    FILE *memFile = fopen(filename, "w");
+    psFree(filename);
+
+    psMemBlock **leaks = NULL;
+    int numLeaks = psMemCheckLeaks(0, &leaks, NULL, true);
+    fprintf(memFile, "# MemBlock Size Source\n");
+    unsigned long total = 0;            // Total memory used
+    for (int i = 0; i < numLeaks; i++) {
+        psMemBlock *mb = leaks[i];
+        fprintf(memFile, "%12lu\t%12zd\t%s:%d\n", mb->id, mb->userMemorySize,
+                mb->file, mb->lineno);
+        total += mb->userMemorySize;
+    }
+    fclose(memFile);
+    psFree(leaks);
+
+    fprintf(stderr, "Memdump %s %d: Memory use: %ld, sbrk: %p\n", name, num, total, sbrk(0));
+    num++;
+}
+
 
 
@@ -210,4 +239,6 @@
     psMetadata *ppsub = psMetadataLookupMetadata(NULL, config->recipes, "PPSUB"); // PPSUB recipe
     int overlap = 2 * psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Overlap by kernel size between consecutive scans
+
+    memDump("start");
 
     // Preparation iteration: Load the sources, and get a target PSF model
@@ -328,4 +359,6 @@
     }
 
+    memDump("psf");
+
     const char *outName = psMetadataLookupStr(NULL, config->arguments, "OUTPUT"); // Output root
     assert(outName);
@@ -389,4 +422,6 @@
         filesIterateUp(config);
         numGood++;
+
+        memDump("match");
     }
     psFree(globalSources);
@@ -405,4 +440,5 @@
 #endif
 
+    memDump("preinitial");
 
     // Stack the convolved files
@@ -524,4 +560,6 @@
             }
         }
+
+        memDump("initial");
 
         // Reset for the second read
@@ -574,4 +612,7 @@
             }
             rejected->data[i] = reject;
+
+            memDump("reject");
+
         }
         psFree(subKernels);
@@ -586,4 +627,6 @@
             return false;
         }
+
+        memDump("prefinal");
 
         // Read convolutions by chunks
@@ -689,4 +732,6 @@
         psFree(weightFits);
 
+        memDump("final");
+
         if (psMetadataLookupBool(&mdok, config->arguments, "PHOTOMETRY")) {
 
@@ -708,4 +753,6 @@
         }
 
+        memDump("phot");
+
         // Statistics on output
         if (stats) {
@@ -713,4 +760,6 @@
             ppStatsFPA(stats, outCell->parent->parent, view, maskBlank, config);
         }
+
+        memDump("stats");
 
         // Put version information into the header
@@ -746,4 +795,6 @@
     }
 
+    memDump("finish");
+
     return true;
 }
