Index: /trunk/ppImage/src/Makefile.am
===================================================================
--- /trunk/ppImage/src/Makefile.am	(revision 16083)
+++ /trunk/ppImage/src/Makefile.am	(revision 16084)
@@ -30,5 +30,6 @@
 	ppImageDefineFile.c \
 	ppImageFileCheck.c \
-	ppImageVersion.c
+	ppImageVersion.c \
+	ppImageMemory.c
 
 ppFocus_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(PSPHOT_CFLAGS) $(PSASTRO_CFLAGS) $(PPSTATS_CFLAGS) $(ppImage_CFLAGS)
@@ -58,5 +59,6 @@
 	ppImageDefineFile.c \
 	ppImageFileCheck.c \
-	ppImageVersion.c
+	ppImageVersion.c \
+	ppImageMemory.c
 
 ppTest_CPPFLAGS = $(PSLIB_CFLAGS) $(PSMODULE_CFLAGS) $(ppImage_CFLAGS)
Index: /trunk/ppImage/src/ppImage.h
===================================================================
--- /trunk/ppImage/src/ppImage.h	(revision 16083)
+++ /trunk/ppImage/src/ppImage.h	(revision 16084)
@@ -35,6 +35,6 @@
     bool doAstromChip;                  // per-chip Astrometry
     bool doAstromMosaic;                // full-mosaic Astrometry
-    bool doStats;			// call ppStats on the image
-    bool replaceMasked;			// fill in masked values with background model
+    bool doStats;                       // call ppStats on the image
+    bool replaceMasked;                 // fill in masked values with background model
 
     // output files requested
@@ -70,8 +70,8 @@
 
     // binning parameters
-    int xBin1;				// x-binning, scale 1
-    int yBin1;				// y-binning, scale 1
-    int xBin2;				// x-binning, scale 2
-    int yBin2;				// y-binning, scale 2
+    int xBin1;                          // x-binning, scale 1
+    int yBin1;                          // y-binning, scale 1
+    int xBin2;                          // x-binning, scale 2
+    int yBin2;                          // y-binning, scale 2
 
     // parameters used by the fringe analysis
@@ -150,5 +150,5 @@
 bool ppImageStats (pmConfig *config, pmChip *chip, const pmFPAview *inputView, const ppImageOptions *options);
 
-// write stats to output file 
+// write stats to output file
 bool ppImageStatsOutput (pmConfig *config, const ppImageOptions *options);
 
@@ -157,5 +157,5 @@
 bool ppImageDetrendFringeMeasure(pmReadout *readout, // Readout to measure
                                  pmCell *fringe, // Fringe cell (each readout is a different component)
-				 const bool isResidual,
+                                 const bool isResidual,
                                  const ppImageOptions *options // Options
     );
@@ -164,5 +164,5 @@
 bool ppImageDetrendFringeSolve(pmChip *scienceChip, // Chip with science
                                const pmChip *refChip, // Chip with reference fringes
-			       const bool isResidual,
+                               const bool isResidual,
                                const ppImageOptions *options // Options
     );
@@ -171,12 +171,12 @@
 bool ppImageDetrendFringeGenerate(pmCell *science, // Science cell
                                   pmCell *fringes, // Fringe cell, one readout per fringe component
-				  const ppImageOptions *options // Options
+                                  const ppImageOptions *options // Options
     );
 
 
 bool ppImageDetrendFringeApply (pmConfig *config, // config
-				pmChip *chip, // science chip
-				const pmFPAview *inputView, // current view
-				const ppImageOptions *options // options
+                                pmChip *chip, // science chip
+                                const pmFPAview *inputView, // current view
+                                const ppImageOptions *options // options
     );
 
@@ -200,3 +200,6 @@
 void ppImageFileCheck (pmConfig *config);
 
+/// Dump memory summary to text file
+void ppImageMemoryDump(const char *description);
+
 #endif
Index: /trunk/ppImage/src/ppImageAstrom.c
===================================================================
--- /trunk/ppImage/src/ppImageAstrom.c	(revision 16083)
+++ /trunk/ppImage/src/ppImageAstrom.c	(revision 16084)
@@ -19,13 +19,15 @@
     PS_ASSERT (input, false);
 
+    ppImageMemoryDump("astrom");
+
     // convert the output sources created by psphot into astrometry objects
     if (!psastroConvertFPA (input->fpa, recipe)) {
-	psError (PSASTRO_ERR_UNKNOWN, false, "error reading input data\n");
-	return false;
+        psError (PSASTRO_ERR_UNKNOWN, false, "error reading input data\n");
+        return false;
     }
 
     if (!psastroAnalysis (config)) {
-	psError (PSASTRO_ERR_UNKNOWN, false, "failure in psastro analysis\n");
-	return false;
+        psError (PSASTRO_ERR_UNKNOWN, false, "failure in psastro analysis\n");
+        return false;
     }
 
@@ -39,4 +41,6 @@
     while ((chip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) {
         psLogMsg ("ppImageLoop", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+
+        ppImageMemoryDump("astrom");
 
         // Output and Close at Chip level
@@ -53,5 +57,5 @@
     }
 
-    // deactivate the PSASTRO files, re-active all else 
+    // deactivate the PSASTRO files, re-active all else
     // XXX do we need a way to activate / deactivate other groups?
     pmFPAfileActivate (config->files, true, NULL);
Index: /trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- /trunk/ppImage/src/ppImageDetrendReadout.c	(revision 16083)
+++ /trunk/ppImage/src/ppImageDetrendReadout.c	(revision 16084)
@@ -92,4 +92,6 @@
     }
 
+    ppImageMemoryDump("detrend");
+
     psFree(detview);
     return true;
Index: /trunk/ppImage/src/ppImageMemory.c
===================================================================
--- /trunk/ppImage/src/ppImageMemory.c	(revision 16084)
+++ /trunk/ppImage/src/ppImageMemory.c	(revision 16084)
@@ -0,0 +1,38 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pslib.h>
+
+#include "ppImage.h"
+
+//#define TESTING
+
+void ppImageMemoryDump(const char *description)
+{
+#ifndef TESTING
+    return;
+#else
+    psMemBlock **leaks = NULL;
+    int numLeaks = psMemCheckLeaks(0, &leaks, NULL, true);
+
+    static int num = 0;
+    psString filename = NULL;
+    psStringAppend(&filename, "%s_%d.txt", description, num++);
+    FILE *fp = fopen(filename, "w");
+    psFree(filename);
+
+    for (int i = 0; i < numLeaks; i++) {
+        psMemBlock *memBlock = leaks[i];
+        fprintf(fp, "%ld : %s at (%s:%d)  ID: %lu  Ref: %lu\n",
+                (unsigned long)memBlock->userMemorySize, memBlock->func, memBlock->file,
+                (int)memBlock->lineno, (unsigned long)memBlock->id, memBlock->refCounter);
+    }
+    psFree(leaks);
+
+    fclose(fp);
+
+    return;
+#endif
+}
Index: /trunk/ppImage/src/ppImagePhotom.c
===================================================================
--- /trunk/ppImage/src/ppImagePhotom.c	(revision 16083)
+++ /trunk/ppImage/src/ppImagePhotom.c	(revision 16084)
@@ -43,7 +43,9 @@
     }
 
+    ppImageMemoryDump("photom");
+
     // the PSPHOT.INPUT file is a temporary file used to carry PPIMAGE.CHIP to psphotReadout
     // XXX not sure that this is needed...
-    pmFPAfileActivate (config->files, false, "PSPHOT.INPUT");
+//    pmFPAfileActivate (config->files, false, "PSPHOT.INPUT");
 
     return true;
