i wonder if i create an object from a class using new operator, and if i dont delete that object when i am finished using it, does it still remain in the memory after the program reaches the and of the main function?
Thanks

Yes, it does remain. If new operator is used u need to delete explicitly.

how do you know it remains?

Yes, it does remain. If new operator is used u need to delete explicitly.

What the fuck are you talking about? When the program ends, nothing remains.

It doesn't remain "in memory" because the process has completed and all of its memory is reclaimed by the operating system.

It doesn't remain "in memory" because the process has completed and all of its memory is reclaimed by the operating system.

That was what i thought too.

Well that depends on your OS.

Your average desktop with an OS which runs each process in a separate address space will reclaim the space when the program exits.

But if you're programming on say a mobile phone, where there is no virtual memory, and not a lot of operating system, then a thread which dies will just leave a big mess in memory with no clear way of fixing it.

so it is a good habit to delete objects that are created by the new keyword although it may not cause problems in some cases.

Like all good habits, you'll do the right thing automatically when it really matters.

But if you write crap code just because you can get away with it, then you're in for a lot of hard lessons later on.

Also, it's important to delete them because they might have other stuff to do (like flushing data to filehandles, and such).

This question has already been answered. Start a new discussion instead.