[mlpack-git] master: Fix memory leak, although I'm not sure it's responsible for the i386 failures. (8983d40)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:04:44 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 8983d407248ce5b3704d2e2349a7fe687bebd8b0
Author: Ryan Curtin <ryan at ratml.org>
Date: Wed Dec 10 04:10:56 2014 +0000
Fix memory leak, although I'm not sure it's responsible for the i386 failures.
>---------------------------------------------------------------
8983d407248ce5b3704d2e2349a7fe687bebd8b0
src/mlpack/core/tree/cosine_tree/cosine_tree.cpp | 18 ++++++++++++++----
src/mlpack/core/tree/cosine_tree/cosine_tree.hpp | 11 +++++++----
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp
index 032122e..5cf5c26 100644
--- a/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp
+++ b/src/mlpack/core/tree/cosine_tree/cosine_tree.cpp
@@ -14,8 +14,8 @@ namespace tree {
CosineTree::CosineTree(const arma::mat& dataset) :
dataset(dataset),
parent(NULL),
- right(NULL),
left(NULL),
+ right(NULL),
numColumns(dataset.n_cols)
{
// Initialize sizes of column indices and l2 norms.
@@ -43,8 +43,8 @@ CosineTree::CosineTree(CosineTree& parentNode,
const std::vector<size_t>& subIndices) :
dataset(parentNode.GetDataset()),
parent(&parentNode),
- right(NULL),
left(NULL),
+ right(NULL),
numColumns(subIndices.size())
{
// Initialize sizes of column indices and l2 norms.
@@ -72,7 +72,9 @@ CosineTree::CosineTree(const arma::mat& dataset,
const double delta) :
dataset(dataset),
epsilon(epsilon),
- delta(delta)
+ delta(delta),
+ left(NULL),
+ right(NULL)
{
// Declare the cosine tree priority queue.
CosineNodeQueue treeQueue;
@@ -87,7 +89,7 @@ CosineTree::CosineTree(const arma::mat& dataset,
// Initialize Monte Carlo error estimate for comparison.
double monteCarloError = root.FrobNormSquared();
- while(monteCarloError > epsilon * root.FrobNormSquared())
+ while (monteCarloError > epsilon * root.FrobNormSquared())
{
// Pop node from queue with highest projection error.
CosineTree* currentNode;
@@ -129,6 +131,14 @@ CosineTree::CosineTree(const arma::mat& dataset,
ConstructBasis(treeQueue);
}
+CosineTree::~CosineTree()
+{
+ if (left)
+ delete left;
+ if (right)
+ delete right;
+}
+
void CosineTree::ModifiedGramSchmidt(CosineNodeQueue& treeQueue,
arma::vec& centroid,
arma::vec& newBasisVector,
diff --git a/src/mlpack/core/tree/cosine_tree/cosine_tree.hpp b/src/mlpack/core/tree/cosine_tree/cosine_tree.hpp
index f4d5aac..c6055ee 100644
--- a/src/mlpack/core/tree/cosine_tree/cosine_tree.hpp
+++ b/src/mlpack/core/tree/cosine_tree/cosine_tree.hpp
@@ -4,7 +4,6 @@
*
* Definition of Cosine Tree.
*/
-
#ifndef __MLPACK_CORE_TREE_COSINE_TREE_COSINE_TREE_HPP
#define __MLPACK_CORE_TREE_COSINE_TREE_COSINE_TREE_HPP
@@ -25,7 +24,6 @@ typedef boost::heap::priority_queue<CosineTree*,
class CosineTree
{
public:
-
/**
* CosineTree constructor for the root node of the tree. It initializes the
* necessary variables required for splitting of the node, and building the
@@ -66,6 +64,11 @@ class CosineTree
const double delta);
/**
+ * Clean up the CosineTree: release allocated memory (including children).
+ */
+ ~CosineTree();
+
+ /**
* Calculates the orthonormalization of the passed centroid, with respect to
* the current vector subspace.
*
@@ -207,10 +210,10 @@ class CosineTree
arma::mat basis;
//! Parent of the node.
CosineTree* parent;
- //! Right child of the node.
- CosineTree* right;
//! Left child of the node.
CosineTree* left;
+ //! Right child of the node.
+ CosineTree* right;
//! Indices of columns of input matrix in the node.
std::vector<size_t> indices;
//! L2-norm squared of columns in the node.
More information about the mlpack-git
mailing list