Hi,
I made an application that draws a lot of outlined circles (100-1000). And it has giant memory leaks (like 4GB after using 30 seconds). It is running 2 loops (event loop and game loop). In game loop it just updates circles position and radius. Sometimes I need to remove some cells. I'm just doing 'cells.erase(cells.begin() + index)' where 'circles' is vector of sf::CircleShape. How can i do it to not leak memory?
Game loop:
struct CellData {
sf::CircleShape cell;
sf::Text name;
sf::Text mass;
double target_x;
double target_y;
double target_size;
};
std::vector<std::pair<..::Client::ClientCell, CellData>> cells;
void draw_cells()
{
std::sort(cells.begin(), cells.end(), [](auto &left, auto &right) {
return left.second.target_size < right.second.target_size;
});
for (int i = 0; i < cells.size(); i++)
{
cells[i].second.cell.setRadius(cells[i].second.target_size);
cells[i].second.cell.setPosition(sf::Vector2f(cells[i].second.target_x - cells[i].second.target_size, cells[i].second.target_y - cells[i].second.target_size));
if (!(cells[i].first.flags & 0x04))
{
cells[i].second.cell.setFillColor(sf::Color(cells[i].first.color[0], cells[i].first.color[1], cells[i].first.color[2]));
}
if (cells[i].first.size > 20)
{
cells[i].second.cell.setOutlineColor(sf::Color(cells[i].first.color[0] / 2, cells[i].first.color[1] / 2, cells[i].first.color[2] / 2));
cells[i].second.cell.setOutlineThickness(10);
}
wnd->draw(cells[i].second.cell);
...
}
}
Cell remove code:
for (int a = 0; a < remove_cells.size(); a++)
{
for (int i = 0; i < cells.size(); i++)
{
if (cells[i].first.id == remove_cells[a]) {
cells.erase(cells.begin() + i);
}
}
}
Thanks.