Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Memory leaks  (Read 1677 times)

0 Members and 1 Guest are viewing this topic.

President

  • Newbie
  • *
  • Posts: 2
    • View Profile
Memory leaks
« on: December 16, 2020, 02:29:46 pm »
I am just using the default code for SFML:
Code: [Select]
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#include <SFML/Graphics.hpp>

int main()
{
    {
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);

        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
            }

            window.clear();
            window.draw(shape);
            window.display();
        }
    }

    _CrtDumpMemoryLeaks();

    return 0;
}

But I my visual studio is finding loads of memory leaks?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Memory leaks
« Reply #1 on: December 16, 2020, 03:35:54 pm »
Well it might make more sense to first familiarize yourself with the tool in use, before assuming that there are actual memory leaks. ;)

SFML has global states that aren't cleaned up until the application terminates, so your dump happens before global states are destroyed, leading to false-positives.
Also do you understand the output of the tool, because if you don't, I don't know exactly what you're hoping to gain from running these checks.
It's way better to stick to good practices like no manual memory management, close to none plain for-loops, etc. than to throw tools at code that produce output that doesn't really tell how to fix a problem ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/