Mistakes in memory management
zixiangliwust opened this issue · comments
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.
-
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;
” -
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;
Dear @zixiangliwust.
Please, could you make a pull request with the suggested changes?