I am trying a database server which keeps a B+ plus tree structure and works on it.
I am trying to find the memory used/leak while executing this process.
I check the memory leak by using ps uax command.
When i execute a delete query i am sure that my code frees up the existing allocation and adds a new allocation.
By doing this is, memory usage should not increase as per my understanding. Because the new allocation will always be less than the previous allocaiton.
But it shows increase in memory when check using ps uax.
Is it that when I call free function and that will not immediately return the memory chunk to free.
Or what is best way to check how many allocations have been made in a process and what size.
I don't know what you are seeing and how you got your conclusions.
free() does not return memory to the OS. malloc() (via brk() ) got the memory from the OS. The idea is that the requested memory stay associated with the process until the process ends. It is too expensive to keep calling brk().
memory leaks look like this from your vantage point :
the process memory keeps on growing over time. For example: the process has 100MB at 9:00am, by 9:05 it has 120MB, by 9:30 200MB -- as long as it runs it gains memory.
There are tools to find memory leaks, things like valgrind, electric fence.