From: westcott Date: Mon, 9 Mar 2009 12:18:46 +0000 (+0000) Subject: fixed memory issue with cluster command X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=1c2f1171eee8879de9dbe03a8a9d9093fc6a1f95 fixed memory issue with cluster command --- diff --git a/clustercommand.cpp b/clustercommand.cpp index f0ef51f..307b774 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -15,13 +15,13 @@ ClusterCommand::ClusterCommand(){ try{ globaldata = GlobalData::getInstance(); - if(globaldata->getSparseMatrix() != NULL) { matrix = new SparseMatrix(*globaldata->getSparseMatrix()); } + if(globaldata->gSparseMatrix != NULL) { matrix = new SparseMatrix(*globaldata->gSparseMatrix); } // Not sure if we want the address or an entire new memory allocation. Might be nice to have new memory so data // doesn't need to be re-read, but then again, it could suck up a ton of memory. Dunno. // if(globaldata->getSparseMatrix() != NULL) { matrix = globaldata->getSparseMatrix(); } - if(globaldata->getListVector() != NULL){ - list = new ListVector(*globaldata->getListVector()); + if(globaldata->gListVector != NULL){ + list = new ListVector(*globaldata->gListVector); rabund = new RAbundVector(list->getRAbundVector()); //rabund->print(cout); } @@ -108,11 +108,8 @@ int ClusterCommand::execute(){ } //delete globaldata's copy of the sparsematrix and listvector to free up memory - SparseMatrix* clearM = NULL; - globaldata->setSparseMatrix(clearM); - ListVector* clearL = NULL; - globaldata->setListVector(clearL); - + delete globaldata->gSparseMatrix; globaldata->gSparseMatrix = NULL; + delete globaldata->gListVector; globaldata->gListVector = NULL; //saves .list file so you can do the collect, rarefaction and summary commands without doing a read.list if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); } diff --git a/errorchecking.cpp b/errorchecking.cpp index b76542a..d827929 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -367,8 +367,8 @@ bool ErrorCheck::checkInput(string input) { } //are you trying to cluster before you have read something - if (((commandName == "cluster") && (globaldata->getSparseMatrix() == NULL)) || - ((commandName == "cluster") && (globaldata->getListVector() == NULL))) { + if (((commandName == "cluster") && (globaldata->gSparseMatrix == NULL)) || + ((commandName == "cluster") && (globaldata->gListVector == NULL))) { cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; errorFree = false; } diff --git a/globaldata.cpp b/globaldata.cpp index b1ac4e8..60a106a 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -16,50 +16,6 @@ GlobalData* GlobalData::getInstance() { } /*******************************************************/ -/******************************************************/ - -ListVector* GlobalData::getListVector() { return gListVector; } -/*******************************************************/ - -/******************************************************/ -void GlobalData::setListVector(ListVector* lv){ - try { - if(gListVector != NULL){ delete gListVector; } - gListVector = new ListVector(*lv); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function setListVector. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*******************************************************/ - -/******************************************************/ - -SparseMatrix* GlobalData::getSparseMatrix() { return gSparseMatrix; } -/*******************************************************/ - -/******************************************************/ -void GlobalData::setSparseMatrix(SparseMatrix* sm){ - try{ - if(gSparseMatrix != NULL){ delete gSparseMatrix; } - gSparseMatrix = new SparseMatrix(*sm); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GlobalData class function setSparseMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*******************************************************/ - /******************************************************/ //This function parses through the option string of the command to remove its parameters void GlobalData::parseGlobalData(string commandString, string optionText){ diff --git a/globaldata.hpp b/globaldata.hpp index 0dc4c34..6070dd7 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -21,8 +21,8 @@ class SAbundVector; class GlobalData { public: static GlobalData* getInstance(); - ListVector* getListVector(); - SparseMatrix* getSparseMatrix(); + ListVector* gListVector; + SparseMatrix* gSparseMatrix; InputData* ginput; OrderVector* gorder; ListVector* glist; @@ -72,9 +72,6 @@ public: void setGroups(string); void setCalc(string); - - void setListVector(ListVector*); - void setSparseMatrix(SparseMatrix*); void clear(); void clearLabels(); void clearAbund(); @@ -90,8 +87,6 @@ private: void operator=( const GlobalData& ); // Disable assignment operator GlobalData(); ~GlobalData(); - ListVector* gListVector; - SparseMatrix* gSparseMatrix; void reset(); //clears all non filename parameters diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 116e670..a9d7721 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -72,8 +72,8 @@ int ReadDistCommand::execute(){ globaldata->gMatrix = matrix; //save matrix for coverage commands }else { read->read(nameMap); - globaldata->setListVector(read->getListVector()); - globaldata->setSparseMatrix(read->getMatrix()); + globaldata->gListVector = read->getListVector(); + globaldata->gSparseMatrix = read->getMatrix(); } return 0; }