From 9e3d69e166b9dc1f072cfcd2b7ef346c23def095 Mon Sep 17 00:00:00 2001 From: Andras Patka Date: Sun, 5 Jan 2020 12:05:11 +0200 Subject: [PATCH] Fixed WireFitQlearn's memory leak issue --- include/WireFitQLearn.h | 2 ++ src/WireFitQLearn.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/WireFitQLearn.h b/include/WireFitQLearn.h index 79d5165..830fb0c 100644 --- a/include/WireFitQLearn.h +++ b/include/WireFitQLearn.h @@ -83,6 +83,8 @@ class WireFitQLearn : public Learner { /** Stores this model in a stream. */ void store(std::ofstream *output); + ~WireFitQLearn(); + protected: // Feeds the state into the network, parses to the output of the network into wire form, and outputs these wires std::vector getWires(State state); diff --git a/src/WireFitQLearn.cpp b/src/WireFitQLearn.cpp index 75dd453..cb97c7f 100644 --- a/src/WireFitQLearn.cpp +++ b/src/WireFitQLearn.cpp @@ -51,6 +51,11 @@ WireFitQLearn::WireFitQLearn(std::ifstream *input) { } +WireFitQLearn::~WireFitQLearn() { + delete modelNet; + delete network; +} + Action WireFitQLearn::chooseBestAction(State currentState) { std::vector action = bestAction(currentState); lastAction = action; @@ -105,6 +110,7 @@ void WireFitQLearn::applyReinforcementToLastAction(double reward, State newState } void WireFitQLearn::reset() { + delete network; network = new net::NeuralNet(modelNet); network->randomizeWeights(); std::cout << "number: " << network->numberOfHiddenNeurons() << "\n";