Out of memory error on Raspbian

Problem

I was compiling some templated C++ on a Raspberry Pi when the compilation failed with this error:

cc1plus: out of memory allocating 66574076 bytes after a total of 98316160 bytes

Solution

The Raspberry Pi had 1GB of RAM. From the error it looked like the compiler needed more memory than that.

It turns out that Raspbian does not use a swap partition. Instead it uses a /var/swap file on the SD card. This is called dphys-swapfile. The default size of this swapfile is 100MB. As can be seen from the error above, this swap space was not enough.

Since I had more than 1GB of free space still available on my SD card, I decided to increase this swapfile. To do that, open the file /etc/dphys-swapfile and increase the number of MB set in the line CONF_SWAPSIZE=100.

Restart the swapfile using the command:

$ /etc/init.d/dphys-swapfile restart

Or alternately you could restart Raspbian.

Tried with: Raspbian 9 and Raspberry Pi B+ Rev3

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.