what happens if i dont delete the object?
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
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
Yes, it does remain. If new operator is used u need to delete explicitly.
how do you know it remains?
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
Yes, it does remain. If new operator is used u need to delete explicitly.
What the #### are you talking about? When the program ends, nothing remains.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
It doesn't remain "in memory" because the process has completed and all of its memory is reclaimed by the operating system.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
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.
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
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.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
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.
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
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.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Also, it's important to delete them because they might have other stuff to do (like flushing data to filehandles, and such).
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177