jMetal / jMetalCpp

A C++ version of jMetal, a Java framework aimed at multi-objective optimization with metaheuristics.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

  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;

Dear @zixiangliwust.

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