Sign in to follow this  
SpacedOut

C++ question

Recommended Posts

SpacedOut    138
if you use 'new' to allocate objects but don't delete them at the end of the program, what will happen? will Windows XP or other OS's clean up the mess, or will the data stay there until you shutdown?

Share this post


Link to post
Share on other sites
dudedbz1    100
I really dont know cuz I never didnt de-allocate used memory. Unless you loaded a huge 3d world, dont worry if you accidentally missed a variable or so... lol.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Very bad things:) Actually I think WinXP is pretty good at cleaning up your mess after a program ends, however older OS aren't so nice (not sure on this though).

It's always a good idea to delete anything you create though no matter what.

Share this post


Link to post
Share on other sites
tompp    126
OS will free up all memory allocated memory by the application - under normal circumstances...
However i cannot stress it enough how bad practice is not to release memory, it leads to the dreaded "Memory leak".
Release every resource you allocate (memory, handles, etc) when you are done with them.

Share this post


Link to post
Share on other sites
rip-off    10979
any modern O.S. wll clean up after you, but it one of the worst programming practises you could have.

if your program is going to run for more than 5 minutes, not deallocating memory will begin to become noticable. particularly in things like dedicated servers, what server admin would like having to restart the program every so often just because you forget delete.

we all make mistakes, but i try be as careful as i can about memory leaks, as they (usually) visibly affect my programs.

think about using a smart pointer or auto pointer ( or whatever its called ) from boost.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
failing to delete allocated memory is sloppy and if you are loading a lot of stuff into memory or that function gets called several thousand times, your program (or others), will start to notice.

Share this post


Link to post
Share on other sites
You have undefined results. If your type has a non-trivial destructor, it most-likely will never get called. Your OS will probably release all of the memory associated with your program when it is terminated, but that should be least of your worries.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this