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.

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.

Now, when u asked, i don't know how i know but i know if u know what i mean.

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

huh?

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).

That is the practice that is taught to beginners. if you make it, you should clean it up.

I agree there will be nothing remaining

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.