OpenClaw High Memory Usage
High RAM usage in OpenClaw almost always comes from the AI model loaded in memory, not from OpenClaw itself. The gateway process uses a modest 200-400 MB. A 7B parameter model at full F16 precision, however, needs 14+ GB β more than most home servers have. The strategies below can cut your model's RAM footprint in half or more without a meaningful quality drop, and work on everything from a Raspberry Pi 5 to a Hetzner VPS.
π Diagnose First
Before optimizing, measure your baseline. On Linux/macOS, run 'ps aux --sort=-%mem | head -20' to see what's consuming the most RAM. On Docker systems, use 'docker stats' to see per-container usage. The Ollama process will typically show the model's full weight in RSS memory. Compare against the table below to understand how much room each optimization buys you.
β Memory Reduction Strategies
Quantization reduces model precision from 16-bit floats to 4-8 bit integers. The quality difference is negligible for most tasks. A Q4_K_M 8B model uses about 5 GB vs 14 GB for F16 β nearly a 3x reduction. Start here before anything else.
The KV cache (the memory used to store conversation history) scales linearly with context length and number of concurrent conversations. Halving context_length from 4096 to 2048 saves roughly 2 GB for a 7B model. Most conversations use far less than 4096 tokens.
By default, Ollama keeps the loaded model in RAM indefinitely. Setting keep_alive: '5m' tells Ollama to unload the model after 5 minutes of inactivity, freeing all GPU/RAM until the next request arrives. The model reloads in 2-4 seconds on SSD systems.
Adding swap lets the OS spill model weights to disk when RAM is full. This is slower than running in RAM but prevents OOM kills. For a 4 GB Pi running a 5 GB model, 4 GB of swap on a fast SD card or USB drive is usually sufficient. Avoid excessive swap on HDDs β the latency is brutal.