954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

da penguin
Newbie Poster
18 posts since Dec 2008
Reputation Points: 36
Solved Threads: 5
 
Yes, it does remain. If new operator is used u need to delete explicitly.


how do you know it remains?

serkan sendur
Postaholic
Banned
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
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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

da penguin
Newbie Poster
18 posts since Dec 2008
Reputation Points: 36
Solved Threads: 5
 
What the #### are you talking about? When the program ends, nothing remains.


huh?

da penguin
Newbie Poster
18 posts since Dec 2008
Reputation Points: 36
Solved Threads: 5
 

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
Team Colleague
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
Banned
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
Team Colleague
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
Banned
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
Team Colleague
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
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

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

mattwaab
Newbie Poster
17 posts since Jan 2009
Reputation Points: 30
Solved Threads: 4
 

I agree there will be nothing remaining

Free_Classified
Newbie Poster
10 posts since Jan 2009
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You