By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

releasing memory when shut down ...

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

Regards
Mangesh .

Apr 18 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
mangesh wrote:
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.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 18 '06 #2

P: 3
hi,
if u r looking for something which removes or flushes ur memory.. for this u could have a destructor which deletes ur objects or u can use a library function flush()...


later
JAY
for more info reach me at
groups.google.com/group/worm-makers
Apr 18 '06 #3

P: 3
again..i forgot to mention one handy function called exit().....u can use this library function...on your call to last destructor...this will release all ur memory and will close all the open files....just make sure u use this function at the end of last destructor....

jay
groups.google.com/group/worm-makers
Apr 18 '06 #4

P: n/a
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 ;).

Apr 18 '06 #5

P: n/a
Phlip wrote:
mangesh wrote:
Is there any function in standard library that can forcefully release
memory associated with a process(application) ?
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
Apr 18 '06 #6

P: n/a
mangesh wrote:
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
Apr 18 '06 #7

P: n/a

mangesh wrote:
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...

Apr 20 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.