Memory Leak

Hi,

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.

Please help me on this.

Regards
Kumaran

I don't know what you are seeing and how you got your conclusions.

  1. 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().

  2. 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.

  3. There are tools to find memory leaks, things like valgrind, electric fence.

THanks Jim.

COuld you assist me how to find the process memory.

I will try to valgrind meanwhile.

Thanks
Kumaran

top (prstat on solaris) works well for this.

Unfortunately i am using Linux.

Please help me for this.

Since you are not on solaris you of course won't have prstat. The other suggestion, top, should be available.

Can anyone tell me how to check the exact amount of memory allocated (by malloc() and calloc() ) to a process in Linux.

Thanks
Kumaran R

Off the top of my head, try looking in the proc filesystem:

cat /proc/meminfo

Cut and paste your results.

I have attached three outputs take at different time.

1st was taken while the process has just started and no table has been opened during that time. (before_open.txt)

2nd was takeb after opening a table, which would consume a considerable amount of memory by malloc() and calloc().(after_open.txt)

3rd was taken after deleting all the rows in that table that would free up lots of previously allocated memory.(after_delete_all.txt)

Please let me know if you need any further info

;D

Better to cut-and-paste wrapped in our BB code tags than attached as text, since I'm on my mobile ;D ... Hard to view as an attachment.