Why am I frequently getting this "Cannot allocate memory" error?

Some process is leaking memory. To get an idea of which process this might be, run

ps --sort -rss -eo rss,pid,command | head

I suggest you start the troubleshooting process by testing the RAM with the built-in utility provided in the GRUB boot menu and eliminate "bad RAM" as a source of the problem.

Memory test Memory test

Memtest86+ Memtest86+

Next, check your system for broken dependencies from a terminal with sudo apt-get check and, if errors are found, rerun the command as sudo apt-get check -f to try and correct them.

If you please, try these steps and report back here with any results.


Hi Dave,

Ok then - we've ruled out the hardware as a source of the problem.

Next, let's examine memory usage and process settings on your computer; run these commands from a terminal prompt:

Display amount of free and used memory

free -m

Display swap usage summary

swapon -s

Display user-process resource limits

ulimit -a

The screenshot below is from a clean installation of 10.04LTS. The particulars to note from the first and second yellow-circled items are in the "used" column, which display memory and swap space available for the operating system to use, i.e., they're not all used up.

The bottom yellow-circled item displays no limits on the number of user-processes, i.e. gFTP or other application for example, that the operating system will permit the user to run.

If you please, try these steps and report back here with any results.


Memory usage and process resource limits

Hi Dave,

The results returned from ps --sort -rss -eo rss,pid,command | head you have posted show the gnome-panel process using roughly 1.8GB of memory which seems a little unusual - that seems like a lot of memory for the Desktop Environment to be using.

You can get a breakdown of the memory the gnome-panel process is using by running the circled commands in the screenshot below and see where it's all going - that may reveal something that stands out.

For comparison, the gnome-panel process on my virtual machine is using 48MB of RAM - granted though, the 10.04 machine in these screenshots is a virtual machine I'm using for tests only and not my own desktop.

pmap from gnome-panel process

Given that, I'll put forward the next step is to isolate the problem to "something" in the Gnome desktop environment.

To test this, try installing the KDE plasma workspace which you'll find in the Ubuntu Software Centre.

kde-plasma desktop environment

Once it's installed, reboot your computer and login with a KDE session instead of Gnome, run your applications as best you can (the desktop is completely different) to see if the "Cannot allocate memory" error repeats itself here.

Simply to be clear, you'll be able to run the same CLI "tests" in a KDE environment as we've done in the Gnome environment and be able to compare results in examining the computer's behaviour between the two.

In KDE, the console application you'll be looking for is xterm which you can find from the Search dialog on the main menu.

xterm pid and pmap for plasma-desktop

I'm going to throw in a little confidence here and say I think we're collectively on the right track to isolating the problem.


After experimenting with having it on and off over the last couple of days, I'm confident in now saying that the problem was a memory leak in the weather indicator portion of the time and date applet. When the weather is displaying, the memory usage increases over time. When the weather is not displaying the memory does not increase.

I guess this is a bug with the weather indicator that should be reported, but reporting bugs on Launchpad is far too convoluted a process for me to undertake.