we*****@yahoo.com wrote:
Hi,
I am trynig to use unix top untility to monitor the size of a program
whose mainly duty is to call new/delete to store/retrieve some
contents. During the load testing, I notice that the size of the
program increases to a certain point, then stablizes, but I didn't
notice that the size of the program decreases with time. Is top utility
program a good one to monitor potential memory leak? When is OS going
to claim the unused heap memory from still running program(s)?
thanks.
This depends on C++ standard library implementation and OS.
In Unix, the standard behaviour for application (and standard C/C++
library behaviour) is to never return memory once allocated from OS, so
obviously "delete"ed memory will never decreases numbers in top.
OTOH, if under load you total memory consumption after while with
constant load stabilizes, it is a good indicator that your C++ code
reuses deleted memory for "new" allocations, so likely there are no
memory leaks.
Mirek