3

I have a program which is working perfectly fine. But it works fine for 5-6 days after that it gets killed SIGKILL. When I observed that memory was the issue, I did strict deallocation wherever allocation is done.

I am using linux top command for monitoring the memory usage.

As of now the program is working fine. But, slowly the VIRT virtual memory attribute in top command is increasing slowly. Why is that so? I am deallocating stuff everywhere it is needed.

Thanks in advance. :)

gpalex
  • 780
  • 1
  • 9
  • 26
Chaitanya
  • 3,047
  • 6
  • 27
  • 45
  • 3
    "I am deallocating stuff everywhere it is needed." if that is true, then your program just /needs/ more memory over the time, however I do not believe that this is true and you should run it through some leak checker. – PlasmaHH Dec 03 '12 at 13:14
  • there are memory-leaks in your program. use **valgrind** to find memory-leaks. – tuxuday Dec 03 '12 at 13:15
  • @PlasmaHH "program just /needs/ more memory over the time". What does that mean? Anyways I m deallocating memory once allocated know. Then the memory consumption shouldn't happen right ? – Chaitanya Dec 03 '12 at 13:19
  • 1
    It is SIGKILL not SIGKELL, so I edited it – Basile Starynkevitch Dec 03 '12 at 13:29
  • @BasileStarynkevitch thank u :) – Chaitanya Dec 03 '12 at 13:30
  • 1
    @Chaitanya: Why do you allocate memory when you deallocate it right away? You surely have some datastructures that contain elements over the runtime of the program that get changed/added to, and for those you surely need memory. If you dont have them, you could replace all your memory allocate by stack objects... – PlasmaHH Dec 03 '12 at 14:02
  • @PlasmaHH Ok. Yes, I have data structures that contain elements over runtime and once I use them, I deallocate them. – Chaitanya Dec 04 '12 at 04:44

2 Answers2

8

If you are developing on Linux, compile your application with g++ -Wall -g, improve it till no warnings are given, and use gdb and valgrind to debug the memory leaks.

You might be perhaps interested in using Boehm's conservative garbage collector.

Read also about memory fragmentation.

Community
  • 1
  • 1
Basile Starynkevitch
  • 1
  • 16
  • 251
  • 479
  • 1
    beat me to it, use valgrind, (also ensure -O0) and use the `--leak-check=full` in valgrind (I would however be vastly in favour of fixing the program rather than adding a GC). – 111111 Dec 03 '12 at 13:15
1

You may check any memory mismanagement with valgrind

Try to run the application for a while and check any possible memory problem.

Tio Pepe
  • 3,021
  • 1
  • 14
  • 21