]> git.donarmstrong.com Git - mothur.git/blobdiff - rarefact.cpp
fixed memory leak in rarefact
[mothur.git] / rarefact.cpp
index c064125c37e846c538075f04d652eca6ec336708..cb4bbbce9a4047ae08b5f37b807be3f78c255d89 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "rarefact.h"
-#include "ordervector.hpp"
+//#include "ordervector.hpp"
 
 /***********************************************************************/
 
@@ -52,11 +52,15 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){
                        for(int i=0;i<displays.size();i++){
                                displays[i]->reset();
                        }
+                       
+                       delete lookup;
+                       delete rank;
                }
 
                for(int i=0;i<displays.size();i++){
                        displays[i]->close();
                }
+               delete rcd;
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -114,10 +118,15 @@ try {
                        
                        //randomize the groups
                        random_shuffle(lookup.begin(), lookup.end());
-               
+                       
+                       vector<SharedRAbundVector*> subset;
                        //send each group one at a time
                        for (int k = 0; k < lookup.size(); k++) { 
-                               rcd->updateSharedData(lookup[0], lookup[k], k+1, numGroupComb);
+                               subset.clear(); //clears out old pair of sharedrabunds
+                               //add in new pair of sharedrabunds
+                               subset.push_back(lookup[0]); subset.push_back(lookup[k]);
+                               
+                               rcd->updateSharedData(subset, k+1, numGroupComb);
                                mergeVectors(lookup[0], lookup[k]);
                        }
 
@@ -125,12 +134,17 @@ try {
                        for(int i=0;i<displays.size();i++){
                                displays[i]->reset();
                        }
+                       
+                       for (int i = 0; i < lookup.size(); i++) {
+                               delete lookup[i];
+                       }
                }
                
                for(int i=0;i<displays.size();i++){
                        displays[i]->close();
                }
-
+               
+               delete rcd;
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the Rarefact class Function getSharedCurve. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";