There are several mistakes in memory management when utilizing pointer. This could lead to breakdown when a larger number of iterations or solving many instances.
1) Mistake when utilizing Solution;
“
Solution parents = new Solution * [number_of_parents];
…….
delete parents;
”
The memory utilized is not released.
The correct way:
“for (int k = 0; k < number_of_parents; k++) {
delete parents[k];
}
delete parents;
”
2) Mistake when utilizing vector<Solution> solutions_;
“
vector<Solution> solutions
…….
solutions.clear();
”
The memory utilized is not released.
The correct way:
“
for (int i = 0; i < solutions.size(); i++) {
delete solutions[i];
}
solutions_.clear();
”
[1] Zixiang Li, Wuhan University of Science and Technology, https://www.researchgate.net/profile/Zixiang-Li-2, zixiangliwust@gmail.com;
There are several mistakes in memory management when utilizing pointer. This could lead to breakdown when a larger number of iterations or solving many instances. 1) Mistake when utilizing Solution; “ Solution parents = new Solution * [number_of_parents]; ……. delete parents; ” The memory utilized is not released. The correct way: “for (int k = 0; k < number_of_parents; k++) { delete parents[k]; } delete parents; ”
2) Mistake when utilizing vector<Solution> solutions_; “ vector<Solution> solutions ……. solutions.clear(); ” The memory utilized is not released. The correct way: “ for (int i = 0; i < solutions.size(); i++) { delete solutions[i]; } solutions_.clear(); ” [1] Zixiang Li, Wuhan University of Science and Technology, https://www.researchgate.net/profile/Zixiang-Li-2, zixiangliwust@gmail.com;