C++ question

Started by
6 comments, last by Polymorphic OOP 18 years, 6 months ago
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?
Advertisement
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.
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
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.
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.
Beware of the Mighty Hamster!
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.
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.
I understand that it's bad practice and I don't do it. I was just curious what would happen.
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.

This topic is closed to new replies.

Advertisement