Arduino fatal error : out of memory

Hello everyone, I really need help on this project. Whenever I try to compile or upload my code, I get this error message:
runtime: out of memory: cannot allocate 536870912-byte block (541065216 in use)
fatal error: out of memory.
I have checked my code various times and I really don’t understand what takes so much space and I have been looking up on the internet for about 3 hours :sob:.
If anyone can tell why this happens and how to fix it I would be very happy.
Thank you.

VoitureAutonome.ino (3.17 KB)

This sounds like a glitch in the Arduino IDE, rather than something in your sketch. It’s likely referring to the memory on your computer rather than the memory on your Arduino board.

Please do this:

  • File > Preferences > Show verbose output during > compilation (check) > OK
  • Sketch > verify/compile
  • After the compilation fails, copy the full contents of the back console window at the bottom of the Arduino IDE window (you might need to scroll up to see it all)
  • Paste it in a reply here using code tags (</> button on the toolbar).

Thank you for your answer.
As you asked this is the entire error message (if this is what you want because it is very long):

runtime: out of memory: cannot allocate 536870912-byte block (541065216 in use)
fatal error: out of memory

runtime stack:
runtime.throw(0x56a0aa, 0xd)
	/home/jenkins/go/src/runtime/panic.go:566 +0x7f
runtime.largeAlloc(0x1ffffe00, 0x112b4001, 0x112abe5c)
	/home/jenkins/go/src/runtime/malloc.go:776 +0xb7
	/home/jenkins/go/src/runtime/malloc.go:669 +0x31
	/home/jenkins/go/src/runtime/asm_386.s:323 +0x5e

goroutine 4 [running]:
	/home/jenkins/go/src/runtime/asm_386.s:277 fp=0x112abdcc sp=0x112abdc8
runtime.mallocgc(0x1ffffe00, 0x5478e0, 0x112abe01, 0x44c3c0)
	/home/jenkins/go/src/runtime/malloc.go:670 +0x7c2 fp=0x112abe34 sp=0x112abdcc
runtime.makeslice(0x5478e0, 0x1ffffe00, 0x0, 0x1ffffe00, 0x0, 0x0, 0x0, 0x0)
	/home/jenkins/go/src/runtime/slice.go:57 +0xd0 fp=0x112abe5c sp=0x112abe34
bytes.makeSlice(0x1ffffe00, 0x0, 0x0, 0x0)
	/home/jenkins/go/src/bytes/buffer.go:198 +0x67 fp=0x112abe8c sp=0x112abe5c
bytes.(*Buffer).ReadFrom(0x1109a8a0, 0x5f3f50, 0x10eb2120, 0xffffe00, 0x0, 0x0, 0x0)
	/home/jenkins/go/src/bytes/buffer.go:170 +0xa7 fp=0x112abee4 sp=0x112abe8c
io.copyBuffer(0x5f3df0, 0x1109a8a0, 0x5f3f50, 0x10eb2120, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/jenkins/go/src/io/io.go:384 +0x129 fp=0x112abf48 sp=0x112abee4
io.Copy(0x5f3df0, 0x1109a8a0, 0x5f3f50, 0x10eb2120, 0x0, 0x0, 0x0, 0x0)
	/home/jenkins/go/src/io/io.go:360 +0x53 fp=0x112abf78 sp=0x112abf48
os/exec.(*Cmd).writerDescriptor.func1(0x0, 0x0)
	/home/jenkins/go/src/os/exec/exec.go:253 +0x57 fp=0x112abfb8 sp=0x112abf78
os/exec.(*Cmd).Start.func1(0x111c4160, 0x10ee2870)
	/home/jenkins/go/src/os/exec/exec.go:370 +0x1d fp=0x112abfd0 sp=0x112abfb8
	/home/jenkins/go/src/runtime/asm_386.s:1612 +0x1 fp=0x112abfd4 sp=0x112abfd0
created by os/exec.(*Cmd).Start
	/home/jenkins/go/src/os/exec/exec.go:371 +0x888

goroutine 1 [syscall, locked to thread]:
syscall.Syscall(0x751eeca0, 0x2, 0x25c, 0xffffffff, 0x0, 0x431e93, 0x10ec5418, 0x481d98)
	/home/jenkins/go/src/runtime/syscall_windows.go:163 +0x4a
syscall.WaitForSingleObject(0x25c, 0xffffffff, 0x10ec5430, 0x0, 0x0)
	/home/jenkins/go/src/syscall/zsyscall_windows.go:693 +0x5f
os.(*Process).wait(0x1102dbf0, 0x0, 0x0, 0x0)
	/home/jenkins/go/src/os/exec_windows.go:18 +0x8b
os.(*Process).Wait(0x1102dbf0, 0x4, 0x0, 0x0)
	/home/jenkins/go/src/os/doc.go:49 +0x2b
os/exec.(*Cmd).Wait(0x111c4160, 0x0, 0x0)
	/home/jenkins/go/src/os/exec/exec.go:434 +0x11c
os/exec.(*Cmd).Run(0x111c4160, 0x0, 0x0)
	/home/jenkins/go/src/os/exec/exec.go:279 +0x58, 0x56c313, 0x15, 0x101, 0x5f4880, 0x614ef0, 0x0, 0x0, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x118*GCCPreprocRunnerForDiscoveringIncludes).Run(0x11128160, 0x10f0e000, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x23c, 0x5f39b0, 0x11128160, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x57, 0x111e4620, 0x538ca0, 0x1102d6e0, 0x111e4660, 0x17, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x1810*ContainerFindIncludes).Run(0x614ef0, 0x10f0e000, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0xdfd, 0x10ec5cc0, 0x22, 0x22, 0x1, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0xe2*Builder).Run(0x10ec5de4, 0x10f0e000, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x89f, 0x0, 0x0)
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x35
	/home/jenkins/workspace/arduino-builder-all-cross/src/ +0x1360
C:\Users\Jean Descazeaud\Desktop\Arduino\arduino-builder returned 2
Error compiling for board Arduino/Genuino Mega or Mega 2560.

That definitely provides more information. Unfortunately I can't provide a real solution. It's possible that there is simply not enough free memory on your computer, which you could try to alleviate by shutting down some other running programs when using the Arduino IDE. Or it could be a glitch. If it's actually trying to allocate 500 MB of memory that seems a bit excessive. This problem is related to one of the tools the Arduino IDE uses, arduino-builder. arduino-builder was added in Arduino IDE 1.6.6 so a workaround would be to use Arduino IDE 1.6.5, which you can download here:

Another workaround would be to use the Arduino Web Editor:

Hopefully someone else might be able to give a better answer.

Okay, thank you very much for your answer I’ll take a look at the links you sent me.

I ended up solving my problem by putting all the code in one tab, which is very hard to read but it works fine so I'm happy :slight_smile: .
Thank you for your help.