Index: /branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c
===================================================================
--- /branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c	(revision 6341)
+++ /branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c	(revision 6342)
@@ -6,5 +6,5 @@
 #include "pmChipMosaic.h"
 
-#define MEM_LEAKS 1
+#define MEM_LEAKS 0
 
 // Compare a value with a maximum and minimum
@@ -156,4 +156,7 @@
             continue;
         }
+
+        psMetadataPrint(cell->concepts, 10);
+
         nCells++;
         gain       += psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN");
@@ -266,7 +269,7 @@
 
         // The images to put into the mosaic
-        images->data[i]  = readout->image;
-        weights->data[i] = readout->weight;
-        masks->data[i]   = readout->mask;
+        images->data[i]  = psMemIncrRefCounter(readout->image);
+        weights->data[i] = psMemIncrRefCounter(readout->weight);
+        masks->data[i]   = psMemIncrRefCounter(readout->mask);
     }
     // Mosaic the images together and we're done
@@ -311,5 +314,5 @@
 
     // Chop off all the component cells, and put in a new one
-    #ifndef MEM_LEAKS
+    #if !MEM_LEAKS
     pmChipFreeCells(chip);
     #else
@@ -321,10 +324,8 @@
     cellConcepts(cell, cells, xBinChip, yBinChip);
 
-    #if 1
+    #if 0
     // XXX For the sake of getting something working, I am not going to bother with sorting out where
     // the double free is coming from.  I'm going to drop the pointers on the array and create a memory
     // leak.  We can clean this up later, when we're not under as much pressure.
-    #else
-
     psArrayElementsFree(chip->cells);
     chip->cells->n = 0;
@@ -337,7 +338,7 @@
     // Want the readouts to contain a subimage, but that subimage is the whole image.
     // This preserves the relationship there was before, where freeing the parent frees the child.
-    readout->image = psMemIncrRefCounter(psImageSubset(image, entire));
-    readout->weight = psMemIncrRefCounter(psImageSubset(weight, entire));
-    readout->mask = psMemIncrRefCounter(psImageSubset(mask, entire));
+    readout->image = psImageSubset(image, entire);
+    readout->weight = psImageSubset(weight, entire);
+    readout->mask = psImageSubset(mask, entire);
     psFree(readout);
 
Index: /branches/eam_rel9_p0/psModules/src/astrom/pmConcepts.c
===================================================================
--- /branches/eam_rel9_p0/psModules/src/astrom/pmConcepts.c	(revision 6341)
+++ /branches/eam_rel9_p0/psModules/src/astrom/pmConcepts.c	(revision 6342)
@@ -11,4 +11,5 @@
 #include "psAdditionals.h"
 
+static bool conceptsInitialised = false;// Have concepts been read?
 static psMetadata *conceptsFPA = NULL;  // Known concepts for FPA
 static psMetadata *conceptsChip = NULL; // Known concepts for chip
@@ -29,5 +30,5 @@
     psMemSetDeallocator(spec, (psFreeFunc)conceptSpecFree);
 
-    spec->blank = blank;
+    spec->blank = psMemIncrRefCounter(blank);
     spec->read = read;
     spec->write = write;
@@ -44,5 +45,7 @@
 {
     assert(blank);
-    pmConceptsInit();
+    if (!conceptsInitialised) {
+        pmConceptsInit();
+    }
 
     pmConceptSpec *spec = pmConceptSpecAlloc(blank, read, write); // The concept specification
@@ -66,4 +69,5 @@
     psMetadataAdd(*target, PS_LIST_TAIL, blank->name, PS_DATA_UNKNOWN | PS_META_REPLACE,
                   "Concepts specification", spec);
+    psFree(spec);                       // Drop reference
 
     return true;
@@ -105,8 +109,11 @@
                          )
 {
-    pmConceptsInit();
+    if (!conceptsInitialised) {
+        pmConceptsInit();
+    }
     psMetadataIterator *specsIter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator on specs
     psMetadataItem *specItem = NULL;    // Item from the specs metadata
     while ((specItem = psMetadataGetAndIncrement(specsIter))) {
+        psTrace(__func__, 9, "Blanking %s...\n", specItem->name);
         pmConceptSpec *spec = specItem->data.V; // The specification
         psMetadataItem *blank = spec->blank; // The concept
@@ -127,5 +134,7 @@
                         )
 {
-    pmConceptsInit();
+    if (!conceptsInitialised) {
+        pmConceptsInit();
+    }
     psMetadataIterator *specsIter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator on specs
     psMetadataItem *specItem = NULL;    // Item from the specs metadata
@@ -157,5 +166,7 @@
                          )
 {
-    pmConceptsInit();
+    if (!conceptsInitialised) {
+        pmConceptsInit();
+    }
     if (! fpa->camera) {
         return false;
@@ -282,33 +293,57 @@
 
         // FPA.NAME
-        pmConceptRegister(psMetadataItemAllocStr("FPA.NAME", "Name of FPA", ""), NULL, NULL,
-                          PM_CONCEPT_LEVEL_FPA);
+        {
+            psMetadataItem *fpaName = psMetadataItemAllocStr("FPA.NAME", "Name of FPA", "");
+            pmConceptRegister(fpaName, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaName);
+        }
 
         // FPA.AIRMASS
-        pmConceptRegister(psMetadataItemAllocF32("FPA.AIRMASS", "Airmass at boresight", 0.0), NULL, NULL,
-                          PM_CONCEPT_LEVEL_FPA);
+        {
+            psMetadataItem *fpaAirmass = psMetadataItemAllocF32("FPA.AIRMASS", "Airmass at boresight", 0.0);
+            pmConceptRegister(fpaAirmass, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaAirmass);
+        }
 
         // FPA.FILTER
-        pmConceptRegister(psMetadataItemAllocStr("FPA.FILTER", "Filter used", ""), NULL, NULL,
-                          PM_CONCEPT_LEVEL_FPA);
+        {
+            psMetadataItem *fpaFilter = psMetadataItemAllocStr("FPA.FILTER", "Filter used", "");
+            pmConceptRegister(fpaFilter, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaFilter);
+        }
 
         // FPA.POSANGLE
-        pmConceptRegister(psMetadataItemAllocF32("FPA.POSANGLE", "Position angle of instrument", 0.0), NULL,
-                          NULL, PM_CONCEPT_LEVEL_FPA);
+        {
+            psMetadataItem *fpaPosangle = psMetadataItemAllocF32("FPA.POSANGLE",
+                                          "Position angle of instrument", 0.0);
+            pmConceptRegister(fpaPosangle, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaPosangle);
+        }
 
         // FPA.RADECSYS
-        pmConceptRegister(psMetadataItemAllocStr("FPA.RADECSYS", "Celestial coordinate system", ""), NULL,
-                          NULL, PM_CONCEPT_LEVEL_FPA);
+        {
+            psMetadataItem *fpaRadecsys = psMetadataItemAllocStr("FPA.RADECSYS",
+                                          "Celestial coordinate system", "");
+            pmConceptRegister(fpaRadecsys, NULL, NULL, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaRadecsys);
+        }
 
         // FPA.RA
-        pmConceptRegister(psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN),
-                          (pmConceptReadFunc)pmConceptRead_FPA_RA, (pmConceptWriteFunc)pmConceptWrite_FPA_RA,
-                          PM_CONCEPT_LEVEL_FPA);
+        {
+            psMetadataItem *fpaRa = psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN);
+            pmConceptRegister(fpaRa, (pmConceptReadFunc)pmConceptRead_FPA_RA,
+                              (pmConceptWriteFunc)pmConceptWrite_FPA_RA, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaRa);
+        }
 
         // FPA.DEC
-        pmConceptRegister(psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN),
-                          (pmConceptReadFunc)pmConceptRead_FPA_DEC,
-                          (pmConceptWriteFunc)pmConceptWrite_FPA_DEC, PM_CONCEPT_LEVEL_FPA);
-
+        {
+            psMetadataItem *fpaDec = psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN);
+            pmConceptRegister(fpaDec, (pmConceptReadFunc)pmConceptRead_FPA_DEC,
+                              (pmConceptWriteFunc)pmConceptWrite_FPA_DEC, PM_CONCEPT_LEVEL_FPA);
+            psFree(fpaDec);
+        }
+
+        // Done with FPA level concepts
     }
     if (! conceptsChip) {
@@ -324,32 +359,56 @@
 
         // CELL.GAIN
-        pmConceptRegister(psMetadataItemAllocF32("CELL.GAIN", "CCD gain (e/count)", NAN), NULL, NULL,
-                          PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellGain = psMetadataItemAllocF32("CELL.GAIN", "CCD gain (e/count)", NAN);
+            pmConceptRegister(cellGain, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellGain);
+        }
 
         // CELL.READNOISE
-        pmConceptRegister(psMetadataItemAllocF32("CELL.GAIN", "CCD read noise (e)", NAN), NULL, NULL,
-                          PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellReadnoise = psMetadataItemAllocF32("CELL.READNOISE",
+                                            "CCD read noise (e)", NAN);
+            pmConceptRegister(cellReadnoise, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellReadnoise);
+        }
 
         // CELL.SATURATION
-        pmConceptRegister(psMetadataItemAllocF32("CELL.SATURATION", "Saturation level (counts)", NAN), NULL,
-                          NULL, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellSaturation = psMetadataItemAllocF32("CELL.SATURATION",
+                                             "Saturation level (counts)", NAN);
+            pmConceptRegister(cellSaturation, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellSaturation);
+        }
 
         // CELL.BAD
-        pmConceptRegister(psMetadataItemAllocF32("CELL.BAD", "Bad level (counts)", NAN), NULL, NULL,
-                          PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellBad = psMetadataItemAllocF32("CELL.BAD", "Bad level (counts)", NAN);
+            pmConceptRegister(cellBad, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellBad);
+        }
 
         // CELL.XPARITY
-        pmConceptRegister(psMetadataItemAllocS32("CELL.XPARITY",
-                          "Orientation in x compared to the rest of the FPA", 0),
-                          NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellXparity = psMetadataItemAllocS32("CELL.XPARITY",
+                                          "Orientation in x compared to the rest of the FPA", 0);
+            pmConceptRegister(cellXparity, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellXparity);
+        }
 
         // CELL.YPARITY
-        pmConceptRegister(psMetadataItemAllocS32("CELL.YPARITY",
-                          "Orientation in x compared to the rest of the FPA", 0),
-                          NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellYparity = psMetadataItemAllocS32("CELL.YPARITY",
+                                          "Orientation in x compared to the rest of the FPA", 0);
+            pmConceptRegister(cellYparity, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellYparity);
+        }
 
         // CELL.READDIR
-        pmConceptRegister(psMetadataItemAllocS32("CELL.READDIR", "Read direction, rows=1, cols=2", 1), NULL,
-                          NULL, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellReaddir = psMetadataItemAllocS32("CELL.READDIR",
+                                          "Read direction, rows=1, cols=2", 1);
+            pmConceptRegister(cellReaddir, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellReaddir);
+        }
 
 
@@ -361,10 +420,18 @@
 
         // CELL.EXPOSURE
-        pmConceptRegister(psMetadataItemAllocF32("CELL.EXPOSURE", "Exposure time (sec)", NAN), NULL, NULL,
-                          PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellExposure = psMetadataItemAllocF32("CELL.EXPOSURE",
+                                           "Exposure time (sec)", NAN);
+            pmConceptRegister(cellExposure, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellExposure);
+        }
 
         // CELL.DARKTIME
-        pmConceptRegister(psMetadataItemAllocF32("CELL.DARKTIME", "Time since flush (sec)", NAN), NULL, NULL,
-                          PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellDarktime = psMetadataItemAllocF32("CELL.DARKTIME",
+                                           "Time since flush (sec)", NAN);
+            pmConceptRegister(cellDarktime, NULL, NULL, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellDarktime);
+        }
 
         // CELL.TRIMSEC
@@ -372,9 +439,10 @@
             psRegion *trimsec = psAlloc(sizeof(psRegion)); // Blank trimsec
             trimsec->x0 = trimsec->y0 = trimsec->x1 = trimsec->y1 = NAN;
-            pmConceptRegister(psMetadataItemAllocPtr("CELL.TRIMSEC", PS_DATA_UNKNOWN, "Trim section",
-                              trimsec),
-                              (pmConceptReadFunc)pmConceptRead_CELL_TRIMSEC,
+            psMetadataItem *cellTrimsec = psMetadataItemAllocPtr("CELL.TRIMSEC", PS_DATA_UNKNOWN,
+                                          "Trim section", trimsec);
+            psFree(trimsec);
+            pmConceptRegister(cellTrimsec, (pmConceptReadFunc)pmConceptRead_CELL_TRIMSEC,
                               (pmConceptWriteFunc)pmConceptWrite_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);
-            psFree(trimsec);
+            psFree(cellTrimsec);
         }
 
@@ -382,24 +450,35 @@
         {
             psList *biassecs = psListAlloc(NULL); // Blank biassecs
-            pmConceptRegister(psMetadataItemAllocPtr("CELL.BIASSEC", PS_DATA_LIST, "Bias sections", biassecs),
-                              (pmConceptReadFunc)pmConceptRead_CELL_BIASSEC,
-                              (pmConceptWriteFunc)pmConceptWrite_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);
+            psMetadataItem *cellBiassec = psMetadataItemAllocPtr("CELL.BIASSEC", PS_DATA_LIST,
+                                          "Bias sections", biassecs);
             psFree(biassecs);
+            pmConceptRegister(cellBiassec, (pmConceptReadFunc)pmConceptRead_CELL_BIASSEC,
+                              (pmConceptWriteFunc)pmConceptWrite_CELL_BIASSEC, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellBiassec);
         }
 
         // CELL.XBIN
-        pmConceptRegister(psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0),
-                          (pmConceptReadFunc)pmConceptRead_CELL_XBIN,
-                          (pmConceptWriteFunc)pmConceptWrite_CELL_XBIN, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellXbin = psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0);
+            pmConceptRegister(cellXbin, (pmConceptReadFunc)pmConceptRead_CELL_XBIN,
+                              (pmConceptWriteFunc)pmConceptWrite_CELL_XBIN, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellXbin);
+        }
 
         // CELL.YBIN
-        pmConceptRegister(psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0),
-                          (pmConceptReadFunc)pmConceptRead_CELL_YBIN,
-                          (pmConceptWriteFunc)pmConceptWrite_CELL_YBIN, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellYbin = psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0);
+            pmConceptRegister(cellYbin, (pmConceptReadFunc)pmConceptRead_CELL_YBIN,
+                              (pmConceptWriteFunc)pmConceptWrite_CELL_YBIN, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellYbin);
+        }
 
         // CELL.TIMESYS
-        pmConceptRegister(psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1),
-                          (pmConceptReadFunc)pmConceptRead_CELL_TIMESYS,
-                          (pmConceptWriteFunc)pmConceptWrite_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellTimesys = psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1);
+            pmConceptRegister(cellTimesys, (pmConceptReadFunc)pmConceptRead_CELL_TIMESYS,
+                              (pmConceptWriteFunc)pmConceptWrite_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellTimesys);
+        }
 
         // CELL.TIME
@@ -409,21 +488,31 @@
             time->sec = 0;
             time->nsec = 0;
-            pmConceptRegister(psMetadataItemAlloc("CELL.TIME", PS_DATA_TIME, "Time of exposure", time),
-                              (pmConceptReadFunc)pmConceptRead_CELL_TIME,
+            psMetadataItem *cellTime = psMetadataItemAlloc("CELL.TIME", PS_DATA_TIME,
+                                       "Time of exposure", time);
+            psFree(time);
+            pmConceptRegister(cellTime, (pmConceptReadFunc)pmConceptRead_CELL_TIME,
                               (pmConceptWriteFunc)pmConceptWrite_CELL_TIME, PM_CONCEPT_LEVEL_CELL);
-            psFree(time);
+            psFree(cellTime);
         }
 
         // CELL.X0
-        pmConceptRegister(psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0),
-                          (pmConceptReadFunc)pmConceptRead_CELL_X0,
-                          (pmConceptWriteFunc)pmConceptWrite_CELL_X0, PM_CONCEPT_LEVEL_CELL);
+        {
+            psMetadataItem *cellX0 = psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0);
+            pmConceptRegister(cellX0, (pmConceptReadFunc)pmConceptRead_CELL_X0,
+                              (pmConceptWriteFunc)pmConceptWrite_CELL_X0, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellX0);
+        }
 
         // CELL.Y0
-        pmConceptRegister(psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0),
-                          (pmConceptReadFunc)pmConceptRead_CELL_Y0,
-                          (pmConceptWriteFunc)pmConceptWrite_CELL_Y0, PM_CONCEPT_LEVEL_CELL);
-
-    }
+        {
+            psMetadataItem *cellY0 = psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0);
+            pmConceptRegister(cellY0, (pmConceptReadFunc)pmConceptRead_CELL_Y0,
+                              (pmConceptWriteFunc)pmConceptWrite_CELL_Y0, PM_CONCEPT_LEVEL_CELL);
+            psFree(cellY0);
+        }
+
+    }
+
+    conceptsInitialised = true;
 
     return init;
Index: /branches/eam_rel9_p0/psModules/src/astrom/pmFPA.c
===================================================================
--- /branches/eam_rel9_p0/psModules/src/astrom/pmFPA.c	(revision 6341)
+++ /branches/eam_rel9_p0/psModules/src/astrom/pmFPA.c	(revision 6342)
@@ -12,6 +12,6 @@
 * XXX: Should we implement non-linear cell->chip transforms?
 *
-*  @version $Revision: 1.1.2.6 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-01-31 20:09:52 $
+*  @version $Revision: 1.1.2.7 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-02-07 21:18:31 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -33,8 +33,9 @@
  *****************************************************************************/
 #define PS_FREE_HIERARCHY 1
+#define PARENT_LINKS 0
+
 static void readoutFree(pmReadout *readout)
 {
     if (readout != NULL) {
-        #if 0
         psTrace(__func__, 9, "Removing readout %lx from cell %lx...\n", (size_t) readout, (size_t) readout->parent);
         if (readout->parent) {
@@ -42,15 +43,21 @@
             for (int i = 0; i < readouts->n; i++) {
                 if (readouts->data[i] == readout) {
-                    pmReadout *tmpReadout = readouts->data[i];
+                    //                    pmReadout *tmpReadout = readouts->data[i];
                     readouts->data[i] = NULL;
+                    #if PARENT_LINKS
+
                     psFree(tmpReadout);
+                    #endif
+
                     break;
                 }
             }
         }
+        psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
+
+        #if PARENT_LINKS
+
+        psFree(readout->parent);
         #endif
-        psTrace(__func__, 9, "Freeing readout %lx\n", (size_t) readout);
-
-        psFree(readout->parent);
 
         psFree(readout->image);
@@ -64,5 +71,4 @@
 {
     if (cell != NULL) {
-        #if 0
         psTrace(__func__, 9, "Removing cell %lx from chip %lx...\n", (size_t)cell, (size_t)cell->parent);
         if (cell->parent) {
@@ -70,16 +76,23 @@
             for (int i = 0; i < cells->n; i++) {
                 if (cells->data[i] == cell) {
-                    pmCell *tmpCell = cells->data[i];
+                    //                    pmCell *tmpCell = cells->data[i];
                     cells->data[i] = NULL;
+                    #if PARENT_LINKS
+
                     psFree(tmpCell);
+                    #endif
+
                     break;
                 }
             }
         }
+        psTrace(__func__, 9, "Freeing cell %lx\n", (size_t)cell);
+
+        pmCellFreeReadouts(cell);
+        psFree(cell->readouts);
+        #if PARENT_LINKS
+
+        psFree(cell->parent);
         #endif
-        psTrace(__func__, 9, "Freeing cell %lx\n", (size_t)cell);
-
-        pmCellFreeReadouts(cell);
-        psFree(cell->parent);
 
         psFree(cell->toChip);
@@ -96,5 +109,4 @@
 {
     if (chip != NULL) {
-        #if 0
         psTrace(__func__, 9, "Removing chip %lx from fpa %lx...\n", (size_t)chip, (size_t)chip->parent);
         if (chip->parent) {
@@ -102,16 +114,23 @@
             for (int i = 0; i < chips->n; i++) {
                 if (chips->data[i] == chip) {
-                    pmChip *tmpChip = chips->data[i];
+                    //                    pmChip *tmpChip = chips->data[i];
                     chips->data[i] = NULL;
+                    #if PARENT_LINKS
+
                     psFree(tmpChip);
+                    #endif
+
                     break;
                 }
             }
         }
+        psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
+
+        pmChipFreeCells(chip);
+        psFree(chip->cells);
+        #if PARENT_LINKS
+
+        psFree(chip->parent);
         #endif
-        psTrace(__func__, 9, "Freeing chip %lx\n", (size_t)chip);
-
-        pmChipFreeCells(chip);
-        psFree(chip->parent);
 
         psFree(chip->toFPA);
@@ -134,5 +153,4 @@
         psFree(fpa->analysis);
         psFree(fpa->camera);
-        #if 1
         //
         // Set the parent to NULL in all fpa->chips before psFree(fpa->chips)
@@ -148,5 +166,5 @@
             }
         }
-        #endif
+        psFree(fpa->chips);
         psFree(fpa->hdu);
         psFree(fpa->phu);
@@ -167,7 +185,12 @@
         psTrace(__func__, 9, "Will now free readout %lx...\n", (size_t)tmpReadout);
         psFree(tmpReadout); // Drop the readout
+        #if PARENT_LINKS
+
         psFree(cell); // Decrement reference counter on cell, since readout->parent isn't held any more
+        #endif
+
     }
     cell->readouts = psArrayRealloc(cell->readouts, 0);
+    cell->readouts->n = 0;
 }
 
@@ -186,7 +209,12 @@
         pmCellFreeReadouts(tmpCell);// Drop all readouts the cell holds
         psFree(tmpCell);            // Drop the cell
+        #if PARENT_LINKS
+
         psFree(chip); // Decrement reference counter on chip, since cell->parent isn't held any more
+        #endif
+
     }
     chip->cells = psArrayRealloc(chip->cells, 0);
+    chip->cells->n = 0;
 }
 
@@ -219,5 +247,12 @@
     tmpReadout->bias = psListAlloc(NULL);
     tmpReadout->analysis = psMetadataAlloc();
+    #if PARENT_LINKS
+
     tmpReadout->parent = psMemIncrRefCounter(cell);
+    #else
+
+    tmpReadout->parent = cell;
+    #endif
+
     if (cell != NULL) {
         cell->readouts = psArrayAdd(cell->readouts, 1, (psPtr) tmpReadout);
@@ -249,5 +284,12 @@
     tmpCell->analysis = psMetadataAlloc();
     tmpCell->readouts = psArrayAlloc(0);
+    #if PARENT_LINKS
+
     tmpCell->parent = psMemIncrRefCounter(chip);
+    #else
+
+    tmpCell->parent = chip;
+    #endif
+
     if (chip != NULL) {
         chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
@@ -282,5 +324,12 @@
     tmpChip->analysis = psMetadataAlloc();
     tmpChip->cells = psArrayAlloc(0);
+    #if PARENT_LINKS
+
     tmpChip->parent = psMemIncrRefCounter(fpa);
+    #else
+
+    tmpChip->parent = fpa;
+    #endif
+
     if (fpa != NULL) {
         fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
Index: /branches/eam_rel9_p0/psModules/src/astrom/pmFPAConstruct.c
===================================================================
--- /branches/eam_rel9_p0/psModules/src/astrom/pmFPAConstruct.c	(revision 6341)
+++ /branches/eam_rel9_p0/psModules/src/astrom/pmFPAConstruct.c	(revision 6342)
@@ -101,9 +101,10 @@
                     psMetadata *cellData = getCellData(camera, cellName);
                     pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell
-                    psFree(cell);
-                    //                  psFree(cellData);
+                    psFree(cell);       // Drop reference
+                    //                    psFree(cellData);   // Drop reference
                 }
                 psFree(cellNamesIter);
                 psFree(cellNames);
+                psFree(chip);           // Drop reference
             }
 
@@ -141,9 +142,9 @@
                     psMetadata *cellData = getCellData(camera, cellType);
                     pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell
-                    //                  psFree(cellData);
+                    //                  psFree(cellData); // Drop reference
                     cell->hdu = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data
 
-                    psFree(chip);
-                    psFree(cell);
+                    psFree(cell);       // Drop reference
+                    psFree(chip);       // Drop reference
                 }
                 psFree(contents);
@@ -172,8 +173,9 @@
                     psMetadata *cellData = getCellData(camera, cellName);
                     pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell
-                    psFree(cell);
-                    //                  psFree(cellData);
+                    psFree(cell);       // Drop reference
+                    //                  psFree(cellData);   // Drop reference
                 }
                 psFree(cellNamesIter);
+                psFree(chip);           // Drop reference
             }
 
@@ -255,5 +257,5 @@
         }
         psFree(chipName);
-        psFree(chip);
+        psFree(chip);                   // Drop reference
 
     } else {
