Memory leaks

I am wondering how can i discover memory leaks?
The reason for that is that when starting the system it takes about 300-350 MB of memory. After running some applications and going back to the “starting point” (same applications running after a restart) my system is using 750 MB.

The weird thing is that all the applications as noted from task manager don’t use more than normally (also the shared memory didn’t increase). There is some memory used somewhere but it doesn’t show up at all, is that some applications misbehaving and not letting the unused memory go and that is the reason why it doesn’t show up as an application using that “invisible” memory?

Valgrind is the tool I’ve seen mentioned but can’t give you any assistance above my pay grade :wink:

Mmm didn’t read that correctly I suspect your best bet would be htop and sort by mem. Similar can be done with top, by pressing F then n. Though to make it useful you may need to W(write a configuration after sorting and setting number of tasks to greater than running). Then running with top -b -n 1 > tasks-sorted.txt

Man top and ? inside top.

It was helpful but what i mean is that i suspect some applications allocating memory and then not disallocating? Like new() and delete() in c++.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

How are you determining you are losing memory? Are you familiar with the
concepts around caching that the OS does by default? This has come up
several times in the various Linux forums (including this one I imagine)
about how ‘Used’ memory is still available because it is used to cache
data that may be used later but which can be dropped in a nanosecond if
needed. Post the output from ‘free’ before/after as you mentioned you
were doing your comparisons.

Good luck.

BenderBendingRodriguez wrote:
> It was helpful but what i mean is that i suspect some applications
> allocating memory and then not disallocating? Like new() and delete() in
> c++.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJKUlFwAAoJEF+XTK08PnB5zMAQANbbxYeA+90BrbsiWyv0JrJC
VXd4P5uURJJZe514/d2aj2jip9S2izcX4PwnzwVt5WDqypNy5PbP8dgjmJ9a/tuR
eo11/13TSi4EioVj1GUWJJv9AAG/JWut2dQdonbwYx9MotdsynoLRc4LaE6nX4ZF
ShT+4+jyWxnJvbUQrAV5TXXZyWSpmBulaQWcBcAWsuFdXBJUVLJ0x+fFRjqiK6hJ
0jOxfWf1Ery77naa7U0tg+RSt6rkXeVmoE7dGYj/7glNFJ0oB5FZwf0xPjZwhN8i
rnUoEYwiFEJU6IJMbbq6DyBo9hUmk2DwfXwdzua07zk/itdC/QcWilr3eItpBjwL
ZP+5YR0Mby4lNnDP+MY3t101/MxCFEGj/E2loQHJZuIRb2gGubFCfu1WkuZ4GaVW
VgqspJ+WmPdAF/Bz8HIdu3V5CFjrRRt21qJzrRRZiu5YUlAVr5nlbF6BAKr4i0je
DBNdu1fuaFFL9mf6r3U0aBU3zjFHcInkD6qnjAbng7Lh1Ij4fzOujNAD7ItJlV5e
y4TqoHeqa6w5JFUvwIuX64MjZshH/SSTFm1MOILSmeg4iObnac7BnPsKuYsxmjnM
clBm600IdKklao3q+OrsRobhubhyOWZn8I0MdwNbbqS4c/Ce7QyW1KYp+uV2uql8
HGPV6E1e195vopOXNtZk
=radn
-----END PGP SIGNATURE-----

I am completely aware how caching works (that’s why i have 8GB of memory rotfl! ).

Both task manager and a memory monitoring widget reports used memory (if i am aware then it does not count the cached memory) so just after a restart the system uses about 300-350 MB of memory (that’s what system monitor and memory widget reports). After some time using some applications it is using a lot more than that using the same apps that were running after restart. The memroy usage of those apps is no different all the times BUT as a fact system reports A LOT more memory being used (to say again, the same set of apps doesn’t use more memory than earlier). Is it possible that some applications allocate some memory in ram and then when closing forget about releasing that allocated memory? Maybe that’s the kernel’s memory usage which i guess is not reported?

Well using htop/top will give you better breakdown than some gui widget…

But I concur with ab you’ve yet to confirm whether it is real memory usage free used-cached-buffers=footprint. But with top you can sort it via shared virtual or resident etc…

Does

echo 3 > /proc/sys/vm/drop_caches

help?

Drop Caches - linux-mm.org Wiki

It did but only by a little margin, there is still difference of about 200MB between clean restart and after using some apps.

I can see that sysinfo shows about 7GB of caches, that is great. You insist about no possible memory leaks as if it was impossible in linux.
free gives me this right now.
total used free buffers cached
Mem: 8180000 796716 7383284 2876 206236

Later on cached will be like 7GB or something but after restart cached will be again low and used will be even lower with the same apps running.

When a process exits, all its memory is deallocated. Have you tried looking at running top and sort by memory? Of my current footprint the top offenders are Firefox and Thunderbird.

I guess i know who is to blame. When starting firefox (3.5) it allocates some memory for itself right? But when immediately closing it there is more memory used than before starting firefox. Also if i am not wrong then those memory showing widgets use top to determine how much memory is used?

No idea, I don’t use those widgets anymore. I look at top when I have to (e.g. servers I maintain, or running VirtualBox). It used to be entertaining watching these widgets showing me memory use, free disk space, traffic through interfaces, ad nauseum, then I thought WTF, I have plenty of RAM and disk space and it all just works, I’m just wasting time fretting over what the machine is doing. Now the only widget showing dynamic status is the clock/calendar. And I waste my time net surfing instead. :slight_smile: