I have been running overnight memory tests on an embedded Linux system. Using vmstat I have observed that the free memory steadily decreases over time. According to some smaps analysis in procfs, the heap of one process grows at roughly the same rate. I suspected a memory leak and found a few spots in the code where new
and delete
are regularly used. However, I did not see a new
calls without matching delete
calls.
I ran the memory test again and this morning cleared the memory caches with the following call
echo 3 > /proc/sys/vm/drop_caches
The free memory listed in vmstat went down to a value close to when the test was started.
Does the kernel regularly reclaim unused heap pages? If so, are there other times besides the one above that this is done? Probably when free memory gets below a certain threshold?