Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit5f4ed7a789dbe338a1113d5498f3038f42b6dfd6 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-12-29 18:44:30 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-12-29 18:44:30 +0200
Files88a77dffb9a74cd8e298ceed1fafa6345d3651a2
uni-projects-5f4ed7a789dbe338a1113d5498f3038f42b6dfd6.tar
uni-projects-5f4ed7a789dbe338a1113d5498f3038f42b6dfd6.tar.gz
uni-projects-5f4ed7a789dbe338a1113d5498f3038f42b6dfd6.zip
Parent2b25a22595660765cf42cba544dfa222871f86a1 (diff)
[SDP/P] Fixed memory leaks
3 files changed, 11 insertions, 0 deletions
-rw-r--r--Year 2/Structures and data algorithms/Project/exb/CityVisit.cpp (renamed from Year 2/Structures and data algorithms/Project/exb/City.cpp)5
-rw-r--r--Year 2/Structures and data algorithms/Project/exb/CityVisit.h2
-rw-r--r--Year 2/Structures and data algorithms/Project/exc/main.cpp4
diff --git a/Year 2/Structures and data algorithms/Project/exb/City.cpp b/Year 2/Structures and data algorithms/Project/exb/CityVisit.cpp
index 1fb04ca..af5128d 100644
--- a/Year 2/Structures and data algorithms/Project/exb/City.cpp
+++ b/Year 2/Structures and data algorithms/Project/exb/CityVisit.cpp
@@ -1,5 +1,10 @@
#include "CityVisit.h"
+CityVisit::~CityVisit() {
+ for (Landmark* l : landmarks)
+ delete l;
+}
+
CityVisit::Landmark* CityVisit::find(const std::string& name) {
for (Landmark* l : landmarks) {
if (l->name == name)
diff --git a/Year 2/Structures and data algorithms/Project/exb/CityVisit.h b/Year 2/Structures and data algorithms/Project/exb/CityVisit.h
index c513542..0dbe1fa 100644
--- a/Year 2/Structures and data algorithms/Project/exb/CityVisit.h
+++ b/Year 2/Structures and data algorithms/Project/exb/CityVisit.h
@@ -21,6 +21,8 @@ class CityVisit {
void visitTheMostInTimeRec(Landmark* currentLandmark, std::deque<Landmark*> currPath, std::deque<Landmark*> unique, int timeLeft, std::deque<Landmark*>& bestPath, unsigned& uniqueCount);
public:
+ ~CityVisit();
+
void pushLandmarks(const std::string& from, const std::string& to, unsigned time);
void parse(std::ifstream& inFile);
diff --git a/Year 2/Structures and data algorithms/Project/exc/main.cpp b/Year 2/Structures and data algorithms/Project/exc/main.cpp
index 95636ce..d482b7e 100644
--- a/Year 2/Structures and data algorithms/Project/exc/main.cpp
+++ b/Year 2/Structures and data algorithms/Project/exc/main.cpp
@@ -69,4 +69,8 @@ int main() {
cb->removeUselessSubBoxes();
cb->print(std::cout) << std::endl;
}
+
+ // Free memory
+ for (Box* b : boxes)
+ delete b;
}