Lkc: fix some memory leaks
This commit is contained in:
parent
2d1f5edc91
commit
48254ba7d7
@ -3,6 +3,14 @@
|
||||
#include "LiftedCircuit.h"
|
||||
|
||||
|
||||
OrNode::~OrNode (void)
|
||||
{
|
||||
delete leftBranch_;
|
||||
delete rightBranch_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
OrNode::weight (void) const
|
||||
{
|
||||
@ -13,6 +21,14 @@ OrNode::weight (void) const
|
||||
|
||||
|
||||
|
||||
AndNode::~AndNode (void)
|
||||
{
|
||||
delete leftBranch_;
|
||||
delete rightBranch_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
AndNode::weight (void) const
|
||||
{
|
||||
@ -28,6 +44,13 @@ int SetOrNode::nrNeg_ = -1;
|
||||
|
||||
|
||||
|
||||
SetOrNode::~SetOrNode (void)
|
||||
{
|
||||
delete follow_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
SetOrNode::weight (void) const
|
||||
{
|
||||
@ -51,6 +74,13 @@ SetOrNode::weight (void) const
|
||||
|
||||
|
||||
|
||||
SetAndNode::~SetAndNode (void)
|
||||
{
|
||||
delete follow_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
SetAndNode::weight (void) const
|
||||
{
|
||||
@ -59,6 +89,15 @@ SetAndNode::weight (void) const
|
||||
|
||||
|
||||
|
||||
IncExcNode::~IncExcNode (void)
|
||||
{
|
||||
delete plus1Branch_;
|
||||
delete plus2Branch_;
|
||||
delete minusBranch_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
IncExcNode::weight (void) const
|
||||
{
|
||||
@ -75,6 +114,13 @@ IncExcNode::weight (void) const
|
||||
|
||||
|
||||
|
||||
LeafNode::~LeafNode (void)
|
||||
{
|
||||
delete clause_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
LeafNode::weight (void) const
|
||||
{
|
||||
@ -113,6 +159,13 @@ LeafNode::weight (void) const
|
||||
|
||||
|
||||
|
||||
SmoothNode::~SmoothNode (void)
|
||||
{
|
||||
Clause::deleteClauses (clauses_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double
|
||||
SmoothNode::weight (void) const
|
||||
{
|
||||
@ -189,6 +242,19 @@ LiftedCircuit::LiftedCircuit (const LiftedWCNF* lwcnf)
|
||||
|
||||
|
||||
|
||||
LiftedCircuit::~LiftedCircuit (void)
|
||||
{
|
||||
delete root_;
|
||||
unordered_map<CircuitNode*, Clauses>::iterator it;
|
||||
it = originClausesMap_.begin();
|
||||
while (it != originClausesMap_.end()) {
|
||||
Clause::deleteClauses (it->second);
|
||||
++ it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool
|
||||
LiftedCircuit::isCompilationSucceeded (void) const
|
||||
{
|
||||
@ -334,6 +400,9 @@ LiftedCircuit::tryUnitPropagation (
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Globals::verbosity > 1) {
|
||||
Clause::deleteClauses (backupClauses_);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -375,6 +444,9 @@ LiftedCircuit::tryIndependence (
|
||||
(*follow) = andNode;
|
||||
return true;
|
||||
}
|
||||
if (Globals::verbosity > 1) {
|
||||
Clause::deleteClauses (backupClauses_);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -417,6 +489,9 @@ LiftedCircuit::tryShannonDecomp (
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Globals::verbosity > 1) {
|
||||
Clause::deleteClauses (backupClauses_);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -493,6 +568,9 @@ LiftedCircuit::tryInclusionExclusion (
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Globals::verbosity > 1) {
|
||||
Clause::deleteClauses (backupClauses_);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -528,6 +606,9 @@ LiftedCircuit::tryIndepPartialGrounding (
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Globals::verbosity > 1) {
|
||||
Clause::deleteClauses (backupClauses_);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -620,6 +701,9 @@ LiftedCircuit::tryAtomCounting (
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Globals::verbosity > 1) {
|
||||
Clause::deleteClauses (backupClauses_);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ class CircuitNode
|
||||
public:
|
||||
CircuitNode (void) { }
|
||||
|
||||
virtual ~CircuitNode (void) { }
|
||||
|
||||
virtual double weight (void) const = 0;
|
||||
};
|
||||
|
||||
@ -35,6 +37,8 @@ class OrNode : public CircuitNode
|
||||
public:
|
||||
OrNode (void) : CircuitNode(), leftBranch_(0), rightBranch_(0) { }
|
||||
|
||||
~OrNode (void);
|
||||
|
||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
||||
|
||||
@ -55,6 +59,8 @@ class AndNode : public CircuitNode
|
||||
AndNode (CircuitNode* leftBranch, CircuitNode* rightBranch)
|
||||
: CircuitNode(), leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
||||
|
||||
~AndNode (void);
|
||||
|
||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
||||
|
||||
@ -73,6 +79,8 @@ class SetOrNode : public CircuitNode
|
||||
SetOrNode (unsigned nrGroundings)
|
||||
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
||||
|
||||
~SetOrNode (void);
|
||||
|
||||
CircuitNode** follow (void) { return &follow_; }
|
||||
|
||||
static unsigned nrPositives (void) { return nrPos_; }
|
||||
@ -98,6 +106,8 @@ class SetAndNode : public CircuitNode
|
||||
SetAndNode (unsigned nrGroundings)
|
||||
: CircuitNode(), follow_(0), nrGroundings_(nrGroundings) { }
|
||||
|
||||
~SetAndNode (void);
|
||||
|
||||
CircuitNode** follow (void) { return &follow_; }
|
||||
|
||||
double weight (void) const;
|
||||
@ -115,6 +125,8 @@ class IncExcNode : public CircuitNode
|
||||
IncExcNode (void)
|
||||
: CircuitNode(), plus1Branch_(0), plus2Branch_(0), minusBranch_(0) { }
|
||||
|
||||
~IncExcNode (void);
|
||||
|
||||
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
||||
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
||||
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
||||
@ -135,6 +147,8 @@ class LeafNode : public CircuitNode
|
||||
LeafNode (Clause* clause, const LiftedWCNF& lwcnf)
|
||||
: CircuitNode(), clause_(clause), lwcnf_(lwcnf) { }
|
||||
|
||||
~LeafNode (void);
|
||||
|
||||
const Clause* clause (void) const { return clause_; }
|
||||
|
||||
Clause* clause (void) { return clause_; }
|
||||
@ -154,6 +168,8 @@ class SmoothNode : public CircuitNode
|
||||
SmoothNode (const Clauses& clauses, const LiftedWCNF& lwcnf)
|
||||
: CircuitNode(), clauses_(clauses), lwcnf_(lwcnf) { }
|
||||
|
||||
~SmoothNode (void);
|
||||
|
||||
const Clauses& clauses (void) const { return clauses_; }
|
||||
|
||||
Clauses clauses (void) { return clauses_; }
|
||||
@ -192,6 +208,8 @@ class LiftedCircuit
|
||||
public:
|
||||
LiftedCircuit (const LiftedWCNF* lwcnf);
|
||||
|
||||
~LiftedCircuit (void);
|
||||
|
||||
bool isCompilationSucceeded (void) const;
|
||||
|
||||
double getWeightedModelCount (void) const;
|
||||
|
@ -327,6 +327,16 @@ Clause::printClauses (const Clauses& clauses)
|
||||
|
||||
|
||||
|
||||
void
|
||||
Clause::deleteClauses (Clauses& clauses)
|
||||
{
|
||||
for (size_t i = 0; i < clauses.size(); i++) {
|
||||
delete clauses[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::ostream&
|
||||
operator<< (ostream &os, const Clause& clause)
|
||||
{
|
||||
@ -445,7 +455,7 @@ LiftedWCNF::LiftedWCNF (const ParfactorList& pfList)
|
||||
|
||||
LiftedWCNF::~LiftedWCNF (void)
|
||||
{
|
||||
|
||||
Clause::deleteClauses (clauses_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -137,6 +137,8 @@ class Clause
|
||||
|
||||
static void printClauses (const vector<Clause*>& clauses);
|
||||
|
||||
static void deleteClauses (vector<Clause*>& clauses);
|
||||
|
||||
friend std::ostream& operator<< (ostream &os, const Clause& clause);
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user