Operating System - HP-UX
1829888 Members
2453 Online
109993 Solutions
New Discussion

Memory allocations not being freed back to OS

 
SOLVED
Go to solution
steveo622
Advisor

Memory allocations not being freed back to OS

Hello,

I am working on a C++ application that is called from JAVA via JNI calls. My application makes very large allocations via operator new. (I am also using the SmartHeap memory manager tool). I then delete these large allocations. However, when looking at the process through the top utility, I don't see the memory size of the process go down. I have already gone through the code removing memory leaks, so that is not the problem. Why does memory (either the SIZE or RES) not decrease? Should I be using another tool other than top to measure memory usage? Am I missing something here?

Any ideas from anyone out there?

Thanks in advance for your help...

Steve Colbert
3 REPLIES 3
Bill McNAMARA_1
Honored Contributor
Solution

Re: Memory allocations not being freed back to OS

have a look at this link:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xd4be0bce6f33d6118fff0090279cd0f9,00.html

for procedure.

Later,
Bill
It works for me (tm)
A. Clay Stephenson
Acclaimed Contributor

Re: Memory allocations not being freed back to OS

Hi Steve:

When you free process memory using free(), the memory is not returned to the OS but rather goes back on the process's heap fore reuse by the same process. You can use the sbrk() system call with a negative vaue to decrease allocated process space but this is not for the faint of heart. If you use sbrk(), you must not use any of the higher-level memory allocation/free functions or absolute chaos including crashes is almost guaranteed.

If it ain't broke, I can fix that.
Olav Baadsvik
Esteemed Contributor

Re: Memory allocations not being freed back to OS

Hello,
What you see is normal.
For a program that frees allocated memory you
will not always see an imediate reduction in
size.
When the system becomes short of memory however this
memory will be returned to the system for re-use and the size of the process will decrease
as you would expect after a call to free.
So this decrease in size will not be observered
if the system is not starved of memory.
I did a test of this about one year ago and
verified this behaviour.
So in short, you should not worry.


Olav