I have a unique_ptrs vector in a derived type store using the base class
std::unique_ptr<std::vector<std::unique_ptr<Variable>>> decisionVariables;
Where the Variable is the superclass, and the derived type is the Route class. My problem is that route instances do not seem to be deleted when the class containing the deciding variables is deleted.
The route is obtained from the variable:
#ifndef __VARIABLE__ #define __VARIABLE__ #include <cstring> #include <ostream> #include <memory> class Variable { public: /** * Returns an independent copy of this decision variable. * * @ret a copy of this decision variable */ virtual std::unique_ptr<Variable> copy () = 0; virtual std::string toString () = 0; }; #endif
Header file for the route:
#ifndef __ROUTE__ #define __ROUTE__ #include <vector> #include <map> #include <cstring> #include <sstream> #include <ostream> #include <memory> #include <set> #include <algorithm> #include "../../../Framework/h/core/Variable.h" class Route : public Variable { private: std::unique_ptr<std::vector<int>> route; double frequency; double routeLength; public: Route (); void add (int); void addToFront (int); void remove (); void removeFromFront (); std::vector<int>::iterator begin(); std::vector<int>::iterator end(); int size (); std::vector<int> getViableNodes (std::shared_ptr<std::map<int, std::unique_ptr<std::vector<int>>>>, int); int front (); int back (); std::string toString (); int get (int); bool containsLink (int, int); bool contains (int); void replace (int, int); void setFrequency (double); double getFrequency (); void setRouteLength (double); double getRouteLength (); std::unique_ptr<Variable> copy (); }; #endif
Is there a way to prevent a serious memory leak at the moment?
source share