I am observing the following behavior in my test program:
I am doing malloc()
for 1 MB and then free()
it after sleep(10)
. I am doing this five times. I am observing memory consumption in top
while the program is running.
Once free()
-d, I am expecting the program's virtual memory (VIRT) consumption to be down by 1 MB. But actually it isn't. It stays stable. What is the explanation for this behavior? Does malloc()
do some reserve while allocating memory?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…