[Avida-SVN] r2171 - development/source/main

matt at myxo.css.msu.edu matt at myxo.css.msu.edu
Thu Nov 1 17:17:39 PDT 2007


Author: matt
Date: 2007-11-01 20:17:39 -0400 (Thu, 01 Nov 2007)
New Revision: 2171

Modified:
   development/source/main/cPhenPlastGenotype.cc
   development/source/main/cPhenPlastGenotype.h
Log:
Fixed memory leak in cPhenPlastGenotype.

Modified: development/source/main/cPhenPlastGenotype.cc
===================================================================
--- development/source/main/cPhenPlastGenotype.cc	2007-11-01 19:34:23 UTC (rev 2170)
+++ development/source/main/cPhenPlastGenotype.cc	2007-11-02 00:17:39 UTC (rev 2171)
@@ -45,10 +45,10 @@
 
 cPhenPlastGenotype::~cPhenPlastGenotype()
 {
-  UniquePhenotypes::iterator it = m_unique.begin();
-  while (it != m_unique.end()){
-    delete static_cast<cPlasticPhenotype*>(*it);  // Remember to cast back
-    ++it;
+  tListIterator<cPlasticPhenotype> ppit(m_plastic_phenotypes);
+  while (ppit.Next()){
+    cPlasticPhenotype* pp = ppit.Get();
+    delete pp;
   }
 }
 
@@ -63,6 +63,7 @@
     UniquePhenotypes::iterator uit = m_unique.find(&test_info.GetTestPhenotype());
     if (uit == m_unique.end()){  // Yes, make a new entry for it
       cPlasticPhenotype* new_phen = new cPlasticPhenotype(test_info, m_num_trials);
+      m_plastic_phenotypes.Push(new_phen);
       m_unique.insert( static_cast<cPhenotype*>(new_phen) );
     } else{   // No, add an observation to existing entry, make sure it is equivalent
       if (!static_cast<cPlasticPhenotype*>((*uit))->AddObservation(test_info)){

Modified: development/source/main/cPhenPlastGenotype.h
===================================================================
--- development/source/main/cPhenPlastGenotype.h	2007-11-01 19:34:23 UTC (rev 2170)
+++ development/source/main/cPhenPlastGenotype.h	2007-11-02 00:17:39 UTC (rev 2171)
@@ -63,7 +63,8 @@
   private:
 
   typedef set<cPhenotype*, cPhenotype::lt_phenotype  > UniquePhenotypes;  //Actually, these are cPlatsicPhenotypes*
-    cGenome m_genome;
+  tList<cPlasticPhenotype> m_plastic_phenotypes;  //This will store a list of our unique plastic phenotype pointers  
+  cGenome m_genome;
     int m_num_trials;  
     UniquePhenotypes m_unique;
     cWorld* m_world;




More information about the Avida-cvs mailing list