This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hello there, first of all I want to say I'm new to the programming, so I expect I'm making a big basic flaw in my code.
Basically, I was wondering why I'm getting a memory leak and how to fix it. To put things simple, whenever I'm switching between two screens, my memory usage goes up each time.
Lets say I have two screens:
- ScreenA
- ScreenB
In the header files of those two screens, I'm creating sf::Font and sf::Text in the private section. Now in my screenmanager/game, if I do:
- Screen *currentScreen; //A pointer to a Screen class. Both ScreenA and ScreenB inherits from Screen.
If I switch screen by doing:
currentScreen = new ScreenA();
delete currentScreen;
currentScreen = new ScreenB(); //In actual code, it switches properly between A and B.
I'll get a memory leak every time I do it. The font and text are causing it, a new font and text are created each time I switch screens. I'm not sure how to unload/dispose/destroy the text and font. I know in Allegro you can destroy it, but in SFML, I'm not sure how to handle it.
I have the source files here: http://www.filedropper.com/screenmemoryleak
Post Details
- Posted
- 10 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/test/commen...