I was having a problem when I tried to render all the pixels in the window separately, so here a simpler version of my problem. Whenever I try to run this code, the memory usage starts growing very fast and reaches up to 365MB before stopping. Why is this taking up so much memory and how can I prevent this?
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window{ sf::VideoMode{ 1024, 960 }, "Pixels", sf::Style::Close };
while (window.isOpen()) {
sf::Event sfmlEvent;
while (window.pollEvent(sfmlEvent)) {
if (sfmlEvent.type == sf::Event::Closed) {
window.close();
}
}
window.clear();
for (int i = 0; i < window.getSize().x; ++i) {
for (int j = 0; j < window.getSize().y; ++j) {
sf::RectangleShape rect{ { 1.0f, 1.0f } };
rect.setPosition(i, j);
window.draw(rect);
}
}
window.display();
}
return 0;
}