fix memory leak

This commit is contained in:
Tiago Gomes 2012-09-11 18:40:41 +01:00
parent fa2c5ee114
commit 86b57e961e
2 changed files with 9 additions and 7 deletions

View File

@ -8,7 +8,8 @@ LiftedBp::LiftedBp (const ParfactorList& pfList)
: pfList_(pfList) : pfList_(pfList)
{ {
refineParfactors(); refineParfactors();
solver_ = new WeightedBp (*getFactorGraph(), getWeights()); createFactorGraph();
solver_ = new WeightedBp (*fg_, getWeights());
} }
@ -16,6 +17,7 @@ LiftedBp::LiftedBp (const ParfactorList& pfList)
LiftedBp::~LiftedBp (void) LiftedBp::~LiftedBp (void)
{ {
delete solver_; delete solver_;
delete fg_;
} }
@ -131,10 +133,10 @@ LiftedBp::getQueryGroups (const Grounds& query)
FactorGraph* void
LiftedBp::getFactorGraph (void) LiftedBp::createFactorGraph (void)
{ {
FactorGraph* fg = new FactorGraph(); fg_ = new FactorGraph();
ParfactorList::const_iterator it = pfList_.begin(); ParfactorList::const_iterator it = pfList_.begin();
for (; it != pfList_.end(); ++it) { for (; it != pfList_.end(); ++it) {
vector<PrvGroup> groups = (*it)->getAllGroups(); vector<PrvGroup> groups = (*it)->getAllGroups();
@ -142,9 +144,8 @@ LiftedBp::getFactorGraph (void)
for (size_t i = 0; i < groups.size(); i++) { for (size_t i = 0; i < groups.size(); i++) {
varIds.push_back (groups[i]); varIds.push_back (groups[i]);
} }
fg->addFactor (Factor (varIds, (*it)->ranges(), (*it)->params())); fg_->addFactor (Factor (varIds, (*it)->ranges(), (*it)->params()));
} }
return fg;
} }

View File

@ -24,7 +24,7 @@ class LiftedBp
vector<PrvGroup> getQueryGroups (const Grounds&); vector<PrvGroup> getQueryGroups (const Grounds&);
FactorGraph* getFactorGraph (void); void createFactorGraph (void);
vector<vector<unsigned>> getWeights (void) const; vector<vector<unsigned>> getWeights (void) const;
@ -34,6 +34,7 @@ class LiftedBp
ParfactorList pfList_; ParfactorList pfList_;
WeightedBp* solver_; WeightedBp* solver_;
FactorGraph* fg_;
}; };