Yet another Memory Leak Issue (memory is still gone when program terminates)- C program on SLES

Posted by user1426181 on Stack Overflow See other posts from Stack Overflow or by user1426181
Published on 2012-09-08T03:04:13Z Indexed on 2012/09/08 3:38 UTC
Read the original article Hit count: 195

Filed under:
|
|

I run my C program on Suse Linux Enterprise that compresses several thousand large files (between 10MB and 100MB in size), and the program gets slower and slower as the program runs (it's running multi-threaded with 32 threads on a Intel Sandy Bridge board). When the program completes, and it's run again, it's still very slow.

When I watch the program running, I see that the memory is being depleted while the program runs, which you would think is just a classic memory leak problem. But, with a normal malloc()/free() mismatch, I would expect all the memory to return when the program terminates. But, most of the memory doesn't get reclaimed when the program completes. The free or top command shows Mem: 63996M total, 63724M used, 272M free when the program is slowed down to a halt, but, after the termination, the free memory only grows back to about 3660M. When the program is rerun, the free memory is quickly used up.

The top program only shows that the program, while running, is using at most 4% or so of the memory.

I thought that it might be a memory fragmentation problem, but, I built a small test program that simulates all the memory allocation activity in the program (many randomized aspects were built in - size/quantity), and it always returns all the memory upon completion. So, I don't think that's it.

Questions:

  1. Can there be a malloc()/free() mismatch that will lose memory permanently, i.e. even after the process completes?

  2. What other things in a C program (not C++) can cause permanent memory loss, i.e. after the program completes, and even the terminal window closes? Only a reboot brings the memory back. I've read other posts about files not being closed causing problems, but, I don't think I have that problem.

  3. Is it valid to be looking at top and free for the memory statistics, i.e. do they accurately describe the memory situation? They do seem to correspond to the slowness of the program.

  4. If the program only shows a 4% memory usage, will something like valgrind find this problem?

© Stack Overflow or respective owner

Related posts about c

    Related posts about memory-leaks