?OUT OF MEMORY ERROR
Commodore Commodore 64
Severity: ModerateWhat Does This Error Mean?
?OUT OF MEMORY ERROR means your BASIC program or variables have used up all available BASIC RAM. The C64 only gives BASIC programs about 38KB of usable RAM. Reduce program size, shorten variable names, or clear unused variables with CLR.
Affected Models
- Commodore 64
- Commodore 64C
- Commodore 128 (C64 mode)
- VICE emulator (C64)
Common Causes
- BASIC program is too large to fit in the 38KB BASIC RAM area
- Too many variables or arrays declared, consuming all available RAM
- Deeply nested FOR-NEXT or GOSUB loops filling the stack
- String variables consuming large amounts of memory
- DIM statement allocating a very large array
How to Fix It
-
Type PRINT FRE(0) and press RETURN to see how much free memory is left.
FRE(0) returns the number of free BASIC bytes. If this shows a negative number, BASIC has wrapped around — the memory is critically full.
-
Shorten variable names to one or two characters.
Each variable name and its value takes memory. Using A instead of SCORE, or B$ instead of PLAYERNAME$ saves RAM across many variables.
-
Remove REM (remark) lines from the program.
Every REM line and comment takes up BASIC RAM even though it does nothing. Removing all REMs from a large program can free hundreds of bytes.
-
Use CLR to free variables if they are no longer needed.
CLR erases all variables and resets the stack. Useful at the start of a new section of a long program where earlier variables are no longer required.
-
For serious programs, consider a machine language routine or a BASIC extension.
38KB is a hard limit for pure BASIC. Larger programs on the C64 used machine language subroutines (called via SYS) to move processing out of BASIC RAM.
Frequently Asked Questions
How much BASIC RAM does the Commodore 64 actually have?
The C64 has 64KB of RAM total, but only about 38KB (38,911 bytes) is available for BASIC programs. The rest is used by the OS, BASIC interpreter, screen memory, colour RAM, and I/O.
Can I extend BASIC memory on the C64?
Yes — memory expanders, RAM cartridges, and BASIC extensions like Simon's BASIC could allow access to more memory. Alternatively, switching to assembly language removes the 38KB constraint entirely.