azmfaridee / mothur

This is GSoC2012 fork of 'Mothur'. We are trying to implement a number of 'Feature Selection' algorithms for microbial ecology data and incorporate them into mother's main codebase.
https://github.com/mothur/mothur
GNU General Public License v3.0
3 stars 1 forks source link

Fix the Memory Not Released Bug #33

Open azmfaridee opened 11 years ago

azmfaridee commented 11 years ago

Memory does not get released after running the program.

In the function int RandomForest::populateDecisionTrees() there is a memory allocation like this:

DecisionTree* decisionTree = new DecisionTree(dataSet, 
globalDiscardedFeatureIndices,
OptimumFeatureSubsetSelector(optimumFeatureSubsetSelectionCriteria), 
treeSplitCriterion, 
featureStandardDeviationThreshold);

But this does not get deleted in any of the further commands because that has been removed from the code in some points.

kdiverson commented 11 years ago

I think DecisionTree already has a destructor. Do we need to call this explicitly?

azmfaridee commented 11 years ago

@kdiverson I know which one you are referring to: https://github.com/darthxaher/mothur/blob/master/decisiontree.hpp#L42

My point is that since in the line: https://github.com/darthxaher/mothur/blob/master/randomforest.cpp#L124

we are creating new decision tree, by using dynamic memory alloc, the destructor will of DecisionTree will not be called, this needs to be done explicitly in RandomForest's destructor, otherwise the memory allocated by new will not be freed automatically.

@mothur-westcott Did not encounter this problem as she is working in Mac OSX, this is because Mac OSX automatically does a memory sweep in OS level which is kinda like a garbage collector regardless of the programming language usage, but in Linux or other OS you'll surely run into bugs because of this, I have tested this and I can tell.

kdiverson commented 11 years ago

@darthxaher https://github.com/darthxaher/mothur/blob/master/randomforest.hpp#L31

the destructor is commented out