Ad Space — Top Banner

Error 020 (Out of Memory)

BBC Micro:bit

Severity: Moderate

What Does This Error Mean?

Error 020 on the Micro:bit means the program has run out of memory. The Micro:bit V1 has only 16KB of RAM, and V2 has 128KB. Simplify your program, use fewer variables, or reduce the size of arrays and strings.

Affected Models

  • BBC Micro:bit V1
  • BBC Micro:bit V2

Common Causes

  • Program uses too many variables or large arrays
  • Long strings consuming available RAM
  • MicroPython program too complex for the V1's 16KB RAM
  • Recursive function calls exhausting the stack
  • Too many radio messages buffered in memory

How to Fix It

  1. Simplify your program — reduce variables and arrays.

    On the V1 with 16KB RAM, every variable counts. Use shorter variable names in MicroPython and avoid storing large lists.

  2. If using MakeCode (blocks), check for large arrays or images.

    Custom images and large arrays use memory. Remove unused images and reduce array sizes.

  3. If using MicroPython: use gc.collect() to free unused memory.

    import gc then gc.collect() runs the garbage collector, freeing memory from objects that are no longer in use.

  4. Upgrade to Micro:bit V2 if possible.

    The V2 has 128KB RAM — 8 times more than the V1. Programs that run out of memory on V1 usually work fine on V2.

Frequently Asked Questions

How do I see what error code the Micro:bit is showing?

The Micro:bit scrolls error codes on its 5x5 LED display. It shows a sad face, then scrolls the error number. Common codes: 020 = out of memory, 050 = heap error, 040 = stack overflow.

How much memory does a MicroPython program have on the Micro:bit?

On the V1: about 8KB of RAM is available for your program after MicroPython loads. On the V2: roughly 100KB is available. MakeCode programs are compiled to machine code and generally use less RAM than MicroPython.