jMetal / jMetalCpp

A C++ version of jMetal, a Java framework aimed at multi-objective optimization with metaheuristics.
64 stars 34 forks source link

Mistakes in memory management #25

Closed zixiangliwust closed 2 years ago

zixiangliwust commented 2 years ago

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;

ajnebro commented 2 years ago

Dear @zixiangliwust.

Please, could you make a pull request with the suggested changes?