releasing memory when shut down ...

M

mangesh

Is there any function in standard library that can forcefully release
memory associated with a process(application) ?

Regards
Mangesh .
 
P

Phlip

mangesh said:
Is there any function in standard library that can forcefully release
memory associated with a process(application) ?

No. That's because you are expected to write clean code that follows (at
least) RAII. Look that up.

Even if there were such a function, it would not call all destructors. Some
of these should release resources other than memory. Read the 'deleteall'
thread, now available in your newsreader, for the complete and gruesome
details.
 
S

SamY

Not in the standard library or STL but that would be available if you
use a 3rd party garbage collector for C++. I don't remember them
offhand but such libraries are available.

And, there are plenty of design patterns which in combinations (based
on your application) would help you minimize such leaks. If you are way
far ahead in youy project that your out of luck for this option, but if
you are just kick starting then consider it ;).
 
K

Kai-Uwe Bux

Phlip said:
No.
Correct.

That's because you are expected to write clean code that follows (at
least) RAII. Look that up.

Clean code is good. RAII is good.

However, those are *not* the reason for the lack of a release_memory() in
the standard. The point is: there is no way at all in standard C++ to
return memory to the operating system -- neither delete() nor free() make
any promisses in this regard. The standard refrains from making any
guarantees about this because it does not want to impose unnecessary
restrictions on the execution environment, in other words: the C++
standard does not force the operating system to take back its memory.

If you need to deal with memory on the OS level, you should use system
calls. But those are platform specific.


Best

Kai-Uwe Bux
 
T

Tom Widmer

mangesh said:
Is there any function in standard library that can forcefully release
memory associated with a process(application) ?

"free" and "delete" are the closest thing offered. Most multitasking
OSes automatically reclaim memory from a process when it is shut down.
Those that don't (e.g. embedded OSes) generally rely on code correctly
pairing "malloc" with "free" (and "new" with "delete").

Tom
 
F

Fei Liu

mangesh said:
Is there any function in standard library that can forcefully release
memory associated with a process(application) ?

Regards
Mangesh .

No, but you can somewhat simulate the behavior with global operator
new, operator new[], operator delete, operator delete[], and operator
deleteall. This will likely crash your application but what you wanted
to do will crash your application anyhow...
 

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

No members online now.

Forum statistics

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

Latest Threads

Top