New filters on the Home Feed, take a look!
view details

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.

1
TEST
Post Body

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

Duplicate Posts
55 posts with the exact same title by 46 other authors
View Details
Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
53,131
Link Karma
783
Comment Karma
52,278
Profile updated: 2 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 years ago