SFML community forums

Help => General => Topic started by: JeZ-l-Lee on February 13, 2009, 06:02:20 pm

Title: App.Close();//Does it free memory used by resources?
Post by: JeZ-l-Lee on February 13, 2009, 06:02:20 pm
App.Close();//Does it free memory used by resources?

Just want to be clear as to what "App.Close();" does.

Thanks....
Title: App.Close();//Does it free memory used by resources?
Post by: Nexus on February 13, 2009, 06:21:23 pm
If you mean Images, Soundstreams and Fonts with resources, then no. They are handled independently from the window.

sf::Window::Close() just closes the window itsself - it won't appear any more on the screen. After invoking the member function Create(), you can use it again.
Title: App.Close();//Does it free memory used by resources?
Post by: Astrof on February 13, 2009, 08:16:51 pm
kinda similar to the above question, but if I have a class that stores Images and such, and I close the program (close the exe) is the memory freed? I guess this is a basic C++ question, but just want to know if I don't explicitly use delete on pointers, does the program delete the data it's using (or like does the OS know that the memory used by the now dead program is available)
Title: App.Close();//Does it free memory used by resources?
Post by: quasius on February 13, 2009, 09:10:53 pm
Quote from: "Astrof"
kinda similar to the above question, but if I have a class that stores Images and such, and I close the program (close the exe) is the memory freed? I guess this is a basic C++ question, but just want to know if I don't explicitly use delete on pointers, does the program delete the data it's using (or like does the OS know that the memory used by the now dead program is available)


To cleanly shutdown an app, you should delete all dynamically allocated memory before closing.  If you don't, the OS will *probably* reclaim the memory anyway, but there's no guarantee and it's considered an ungraceful exit.
Title: App.Close();//Does it free memory used by resources?
Post by: Nexus on February 13, 2009, 09:15:02 pm
@ Astrof
That depends on the storage class of your variables. Do you request the free store (sometimes called "heap") - i.e. new? Memory you allocate with new has to be deallocated with delete.

If you just have variables on the stack (automatic storage class), they are released by leaving the scope. The memory of variables declared static or global (static storage class) are freed at the end of the program.
Title: App.Close();//Does it free memory used by resources?
Post by: Astrof on February 14, 2009, 12:11:12 am
hmm ok, thanks, I guess I'll have to be careful in my code then.