How to unload a model and free the VRAM
Start with what is loaded right now, then decide whether you want a one-off cleanup or a different default.
- See what is loaded: ollama ps
- Unload one model now: ollama stop gemma4:12b
- Unload a model as soon as it answers: add keep_alive = 0 to the request body in the API
- Change the default for the whole server: [Environment]::SetEnvironmentVariable('OLLAMA_KEEP_ALIVE', '1m', 'User') and then quit Ollama from the tray and open it again
- Check that memory went back down: nvidia-smi --query-gpu=memory.used --format=csv
Commands from Ollama 0.40.14 and the NVIDIA driver. OLLAMA_KEEP_ALIVE accepts a duration such as 2m or 30s, or 0; according to the documentation, a negative number keeps the model loaded indefinitely.
How to check that the GPU is really free
After unloading, ollama ps should list no model, and nvidia-smi (or “Dedicated GPU memory” in Task Manager) should return to what it was at rest, before you used Ollama. Keep in mind that Windows and your other programs already use some VRAM: on our test PC the desktop took about 2.9–3.0 GB at rest.
Why it happens: OLLAMA_KEEP_ALIVE is 5 minutes by default
The server configuration Ollama prints in its log says it directly: OLLAMA_KEEP_ALIVE:5m0s. That is five minutes, as the official documentation confirms (Ollama FAQ). It’s a sensible default for chatting, and a bad one if you switch between Ollama and a game, a video editor or a second model.
The cost is real and silent. With three models loaded at once and a game open on the same PC, graphics card memory reached 15.6 of 16 GB, and gemma4:12b, which normally generated 111–113 tokens per second, dropped to about 3.8. No error, just roughly thirty times slower.
The rule that matters more than any variable: don’t keep several models loaded if you don’t need them at the same time. If you compare models, do it one after another, unloading the previous one first.
The other side: the first reply of the day is slow
Unloading sooner means loading more often, and loading takes time: Ollama moves the model from disk into memory before answering, and load_duration in the API response shows it. On our test PC, the first loads and the later ones looked like this.
- qwen3.5:4b: 36.8 s on its first load, right after downloading it; 3.7–4.3 s on later loads.
- qwen3.5:9b: 6.8 s the first time; 4.8–5.9 s later.
- gemma4:12b: 23.5 s the first time; 6.6 s later.
- What helps: keep your models on an SSD (OLLAMA_MODELS moves them; the installed app keeps them under %USERPROFILE%\.ollama by default), and ask a short question right after starting so the load happens while you do something else.
If the model is still slow after freeing the VRAM
Check these, in order of likelihood. First, the GPU is shared with something else: other loaded models, a game, an editor, even a browser with many video tabs. Second, you raised the context and the model no longer fits entirely on the card; see Ollama context length on Windows. Third, Ollama fell back to the processor after a driver or version change; see Ollama not using the GPU on Windows.
One trap when measuring: if you repeat exactly the same text, Ollama reuses what it already processed, and the reading speed jumps to 8,000–13,000 tokens per second. The model didn’t get faster. Change the beginning of the text each time, or look only at the first run.
Frequently asked questions
How long does Ollama keep a model loaded?Five minutes after the last request by default (OLLAMA_KEEP_ALIVE:5m0s in the log). You can change it with OLLAMA_KEEP_ALIVE or per request with keep_alive.
How do I unload all Ollama models at once?Run ollama ps and then ollama stop for each model it lists. The book’s package includes a free-vram.ps1 script that does it in one go.
Does keep_alive = 0 make every answer slower?Every request then has to load the model again, so you pay the load time each time. It suits occasional use; for a chat session, a short value such as 1m is a better balance.
Why is my game stuttering after using Ollama?Because the model is probably still in VRAM. ollama ps will show it; ollama stop frees it.