Does space reserved by new automatically get deleted at prog end?

M

megiddo

Does the space you reserve with the 'new' operator automatically get
returned to the system when the program ends?
 
A

Andre Kostur

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
Does the space you reserve with the 'new' operator automatically get
returned to the system when the program ends?

That's operating-system specific.
 
M

Matt Wharton

Does the space you reserve with the 'new' operator automatically get
returned to the system when the program ends?

Depends on your OS. AFAIK, most of your modern, garden variety OSes will
behave this way though.

-Matt
 
J

Jonathan Mcdougall

Does the space you reserve with the 'new' operator automatically get
returned to the system when the program ends?

Depends, but if you're asking that question, I would say no. That's why
there's a delete operator.


Jonathan
 
R

Rolf Magnus

Does the space you reserve with the 'new' operator automatically get
returned to the system when the program ends?

As others pointed out, OSes _usually_ do that for you. But note that they
won't call your objects' destructors, so if you have e.g. cached any data
to be written to disk on object destruction, that data will be lost, or
network connections might not be shut down properly, but just terminated
instead, ...
 
M

Major_Small

as others have pointed out, the OS may, but it's just good practice to
keep track of everything you allocate and deallocate it when you don't
need it anymore...
 
P

Puppet_Sock

Does the space you reserve with the 'new' operator automatically get
returned to the system when the program ends?

In addition to what others have said: It's very good policy
to program cleanly, because a chunk of code won't necessarily
always be a stand-alone program. If your code does not tidy
after itself, then gets put in a library, it will be a memory
leak. And people will be upset with you.
Socks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top