I have coded a program in C++ for Ubuntu Server (64-Bit) which should run 24/7. The Server has 2GB RAM, but apparently my program is allocating too much memory.
This is the output of top
after about 2 hours
top - 13:35:57 up 1:39, 1 user, load average: 0.15, 0.13, 0.08
Tasks: 68 total, 2 running, 66 sleeping, 0 stopped, 0 zombie
%Cpu(s): 1.9 us, 5.7 sy, 0.0 ni, 92.3 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem: 2050048 total, 540852 used, 1509196 free, 34872 buffers
KiB Swap: 1509372 total, 0 used, 1509372 free. 93060 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
902 root 20 0 1019896 364920 4492 S 13.1 17.8 13:07.03 Bether
How you can see my code already consumes 17.8% memory. At some point, the server will crash because it has no memory left.
My problem is that the program should not do that, but I can't find out where the memory gets allocated and not free'd anymore. Is there a tool, maybe even inside gdb
, to find out where the program allocates the most memory?
Thanks in advance!
Check out Valgrind, it should be in the Ubuntu repository. it can give you detailed information about memory usage in C++ programs. Kind of like a debugger for memory usage.
valgrind --tool=memcheck <your_app> <your_apps_params>
Also check out ccmalloc, NJAMD, LeakTracer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With