Ollama RAM Usage After Unloading Model: Why It Stays High
Ollama RAM usage after unloading model still high? Learn why memory stays occupied, how to free it safely, and when it points to a real memory leak.

You finish using a local AI model, unload it from Ollama, and check your computer’s memory usage. Surprisingly, several gigabytes still appear occupied. Did Ollama fail to release the model, or is your operating system holding the memory for another reason?
The quickest fix: Run ollama ps to identify loaded models, then execute ollama stop MODEL_NAME using the exact installed model name. Check again. If the model disappears but system RAM remains high, investigate operating-system memory accounting before restarting Ollama or clearing caches.
This guide explains how to distinguish normal memory behavior from an actual resource problem, verify unloading on Windows, macOS, and Linux, and configure Ollama to release models automatically.
What Happens to RAM When Ollama Unloads a Model?
Ollama runs local language models using system RAM, GPU memory (VRAM), or a combination of both. During inference, memory is needed for several components, including model weights, runtime allocations, and the key-value (KV) cache used to process token sequences.
When a model is unloaded successfully, its active inference resources should be released. However, unloading a model does not necessarily return every system-wide memory indicator to the value it showed before the model was opened.
That distinction matters because three different situations can produce similar-looking memory graphs.
Scenario A: The model is still intentionally loaded
According to the official Ollama FAQ, models normally remain loaded for five minutes after their last request.
This retention period improves responsiveness during repeated conversations by avoiding unnecessary model reloads.
Closing a terminal conversation or ending a request does not automatically mean that Ollama has unloaded the model.
Scenario B: The model is unloaded, but cached memory remains
Operating systems use otherwise available RAM to cache recently accessed files. Loading a large model can populate that cache with model data.
Even after the inference process releases its memory mappings, the operating system may retain some cached file pages for possible future use.
That memory is different from an actively running model’s private allocations. Much of it can be reclaimed when applications require more memory.
Scenario C: A process is still holding memory
In a less routine case, an inference runner may remain active, another application may be using the model, or a software defect may prevent resources from being released as expected.
The critical question is therefore not simply whether RAM usage looks high. It is whether the supposedly unloaded model still has active memory allocations that create meaningful pressure on the system.
📊 The Ollama Memory Lifecycle
Conceptual process diagram — not a quantitative measurement.
Important: The final stage does not imply that all retained RAM is harmless. If an inference process remains active or memory pressure persists, further investigation is necessary.
How to Check Whether Ollama Actually Unloaded the Model
Before changing memory settings, determine whether Ollama still considers the model loaded.
Step 1: List currently loaded models
Open a terminal or command prompt and run:
ollama ps
This command lists models currently loaded into memory. Depending on the installed version, its columns may include the model name, memory size, processor allocation, context, and remaining retention time.
If your model appears in this list, it has not completed unloading.
If the list is empty, Ollama is not reporting an active loaded model. That is useful evidence, but it does not independently prove that every related process has exited or that all system caches have been reclaimed.
Step 2: Unload the specific model
Use the model name displayed by ollama ps:
ollama stop llama3.2
Here, llama3.2 is an example. Replace it with your actual model name and tag.
Then run:
ollama ps
The target model should disappear once unloading completes. If a request is still processing, resource release may not be instantaneous.
⚠️ Do not confuse unloading with deleting. The ollama stop command releases a loaded model from memory. The ollama rm command removes a locally installed model from storage. Deleting a model is unnecessary when the objective is simply to free RAM.
Step 3: Verify through the Ollama API
For developers and automated workflows, Ollama provides a dedicated endpoint for identifying running models:
curl http://localhost:11434/api/ps
The endpoint returns a JSON object containing a models array. When no models are loaded, that array should be empty.
For loaded models, the response can include size, size_vram, and expires_at fields. These identify Ollama’s reported model allocation and expiration information; they are not a substitute for measuring all memory used by the operating system or GPU driver.
Consult the official running-models API reference for the current response structure.
Why RAM Can Remain High Even After Ollama Shows No Loaded Models
One of the most common troubleshooting mistakes is treating all occupied physical memory as memory that cannot be reused.
Modern operating systems manage several categories of memory, and they do not necessarily display them in the same way.
◉ File cache versus active model memory
Consider a hypothetical example: A computer has 16 GB of RAM. After opening and unloading a language model, its memory dashboard still shows a large amount of RAM in use.
There are two very different possible explanations.
In the first, the model is no longer running, but the operating system retains recently read model data in its file cache. That cache can potentially be reused by other applications.
In the second, a surviving Ollama-related process still holds substantial private memory or active mappings, preventing that capacity from becoming available.
Both situations may produce high headline memory usage. Only the second necessarily points toward an incomplete resource release.
This distinction is especially important on Linux, where free -h displays separate memory categories.
free -h
The available column estimates how much memory can be allocated to new applications without swapping. It accounts for reclaimable caches and other kernel considerations.
Therefore, a low free value alongside a healthy available value does not automatically indicate a memory shortage.
This behavior is documented in the Linux free(1) manual.
◉ Memory-mapped model files
Large model runtimes may use memory-mapped files, often called mmap, to access model weights.
Memory mapping lets a process access file contents through virtual memory rather than requiring every byte to be copied into a separate application-managed buffer.
Some mapped file pages become resident in physical RAM as they are accessed. Their accounting can differ from private anonymous memory allocations.
After the mapping is closed, file-backed pages may remain available in the operating system’s cache. This explains why a system-wide memory graph may not return immediately to its earlier appearance.
However, mapped memory is not inherently equivalent to freely reclaimable cache while a process still depends on it. The relevant process state and the operating system’s memory-pressure indicators must also be checked.
A Diagnostic Matrix: Normal Caching or a Real Memory Problem?
Rather than assuming that every high-memory reading requires intervention, use the following symptom-based comparison.
📊 Ollama RAM Troubleshooting Matrix
Qualitative diagnostic guide. These are possible explanations, not automatic diagnoses.
| Observed behavior | Possible explanation | Next check |
|---|---|---|
| Model still appears in ollama ps | Keep-alive timer or active request | Stop the model and verify again |
| No model shown; Linux available RAM is healthy | Potentially reclaimable file cache | Compare available memory and cache |
| No model shown; runner still consumes substantial private memory | Delayed or incomplete cleanup | Inspect process details and server logs |
| RAM rises after repeated AI requests | Growing cache, concurrency, or possible leak | Repeat controlled tests with the same configuration |
| VRAM remains occupied after unloading | Other GPU processes, delayed cleanup, or driver allocations | Inspect GPU processes and utilization |
The strongest diagnosis comes from comparing model residency, process memory, system availability, and application behavior together—not from a single percentage.
How to Release Ollama Memory Immediately Using keep_alive
If your objective is to minimize idle RAM consumption, you can configure Ollama to unload a model immediately after the request finishes.
Ollama supports a keep_alive parameter in both the /api/generate and /api/chat endpoints.
✅ Unload immediately after generating a response
For a single API request:
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Explain how RAM caching works.",
"stream": false,
"keep_alive": 0
}'
Setting keep_alive to 0 instructs Ollama to unload the model after its response completes.
This is useful when running occasional local inference requests on a computer that also handles gaming, video editing, development, or other memory-intensive applications.
✅ Unload an already loaded model through the API
You can also send an empty request with keep_alive set to zero:
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"keep_alive": 0
}'
For a successful unload request, Ollama’s API can report "done_reason": "unload".
The same general mechanism is documented for chat requests. See the Ollama Generate API documentation.
Remember that API requests may originate from other clients, including third-party chat interfaces. If another client keeps submitting requests or explicitly chooses a longer retention period, the model may be loaded again.
Configure OLLAMA_KEEP_ALIVE to Reduce Idle RAM Consumption
Instead of setting keep_alive on every request, Ollama supports a server-wide environment variable:
OLLAMA_KEEP_ALIVE
The official documentation supports duration values, numbers interpreted as seconds, zero for immediate unloading, and negative values for indefinite idle retention.
Keep-Alive Settings Explained
| Value | Behavior | Suitable situation |
|---|---|---|
0 |
Unload after each request | Occasional inference |
30s |
Retain for 30 seconds | Short request bursts |
5m |
Retain for five minutes | Normal interactive sessions |
-1 |
Disable idle timeout | Dedicated inference workloads |
These durations are configuration values, not measured memory savings. An API request's own keep_alive value overrides the server-wide default, and models may still be unloaded for resource-management reasons.
✅ Configure Ollama on Linux with systemd
If Ollama runs as a systemd service, edit its service configuration:
sudo systemctl edit ollama.service
Add:
[Service]
Environment="OLLAMA_KEEP_ALIVE=0"
Save the configuration, then reload and restart the service:
sudo systemctl daemon-reload
sudo systemctl restart ollama
Finally, inspect the loaded models:
ollama ps
⚠️ Restarting the service interrupts active inference sessions. Apply the change during a suitable maintenance window if other users or applications depend on the server.
Setting the environment variable only in your personal shell may not affect an Ollama service already running under systemd. The variable needs to be present in the server process’s environment.
✅ Configure Ollama on Windows
For the standard Windows application:
- Quit Ollama using its system-tray menu.
- Open Windows Settings and search for Edit environment variables for your account.
- Create a user environment variable named
OLLAMA_KEEP_ALIVE. - Set its value to
0, or choose a short retention interval such as30s. - Save the settings and launch Ollama again.
Changes to the environment of an already running application are not automatically applied. Restart Ollama after modifying the variable.
✅ Configure Ollama on macOS
When running Ollama as the standard macOS application, the official FAQ documents configuring its environment through launchctl.
For example:
launchctl setenv OLLAMA_KEEP_ALIVE "0"
Quit Ollama completely, then reopen the application so the new environment setting can take effect.
If you start ollama serve manually rather than using the packaged application, configure the environment of that server process instead.
Diagnose Persistent RAM Usage on Windows, macOS, and Linux
The correct monitoring tool depends on your operating system. A model can be fully unloaded while the computer still reports substantial cached memory.
➫ Windows: Compare the model list with Task Manager
Open Task Manager using Ctrl + Shift + Esc.
Check the Processes, Details, and Performance sections. Look for Ollama-related processes and inspect system memory availability.
On the memory performance page, distinguish memory actively used by applications from cached or standby memory when the available indicators permit that comparison.
Then:
- Record memory availability before running the model.
- Load the model and send a representative request.
- Unload it using
ollama stop. - Confirm that it disappears from
ollama ps. - Check whether substantial private memory remains attributed to an Ollama process.
Microsoft’s process memory documentation explains why a process’s working set is a more specific measurement than the system’s overall used-memory percentage.
If the Ollama application remains open with a relatively small memory footprint, that alone is not evidence that a language model is still resident.
➫ macOS: Examine Memory Pressure and Swap Used
On macOS, open Activity Monitor and select the Memory tab.
Pay particular attention to Memory Pressure, Swap Used, and the memory attributed to Ollama-related processes.
Macs with Apple silicon use unified memory, which is shared across CPU and GPU workloads. Consequently, model allocations do not follow the same separate RAM-versus-dedicated-VRAM pattern found on many desktop NVIDIA systems.
A large amount of used memory is not, by itself, proof of a problem. Apple’s Activity Monitor documentation explains that memory pressure considers availability, swapping, wired memory, and cached files.
If memory pressure remains elevated and swap usage grows during otherwise idle periods, investigate the processes holding memory and whether inference requests are still running.
For a more detailed process view, experienced users can inspect Ollama-related processes in Terminal:
ps aux | grep '[o]llama'
The result must be interpreted carefully: the Ollama server can legitimately remain running while no model is loaded.
➫ Linux: Check available RAM, processes, and service state
Start with:
free -h
Then inspect Ollama-related processes:
ps aux | grep '[o]llama'
For installations using systemd, inspect the service:
systemctl status ollama
If memory appears to be increasing unexpectedly, compare the process’s resident memory across repeated requests and after unloading.
Linux administrators can obtain more detailed process memory accounting from /proc, including proportional set size (PSS) and private memory metrics where supported.
Those measurements are particularly useful when shared file-backed pages make a simple RSS comparison misleading.
A running service is not the same thing as a loaded model. Avoid restarting the entire service until the evidence indicates that normal model unloading is insufficient.
What If Ollama Still Uses Too Much RAM After Unloading?
If the model disappears from ollama ps but a runner continues holding substantial non-reclaimable memory, more investigation is justified.
➫ Check for another active request
Applications such as local chat interfaces, coding assistants, and automation tools can send requests to Ollama independently of the terminal you are watching.
Temporarily stop those clients and repeat the unload test.
Make sure an outstanding generation request is not still being processed. Otherwise, you may mistake a busy runner for a process that failed to shut down.
➫ Inspect the server logs
Ollama provides official troubleshooting instructions for each major operating system.
On Linux with systemd:
journalctl -u ollama --no-pager -n 100
On macOS, the standard log file can be inspected with:
cat ~/.ollama/logs/server.log
On Windows, inspect the Ollama logs under:
%LOCALAPPDATA%\Ollama
Look for relevant errors, runner termination problems, repeated model loading, or unexpected resource allocation behavior.
See Ollama’s official troubleshooting guide for platform-specific log locations and diagnostic procedures.
➫ Consider version-specific memory-release bugs
Not every persistent memory problem is caused by incorrect configuration.
For example, a 2026 Ollama GitHub issue concerning macOS MLX runners described a case in which ollama stop appeared to succeed while a runner process reportedly remained resident.
That report does not establish a universal defect. The issue was closed, and maintainers reported different results during reproduction attempts.
Its value is diagnostic: if the model list is empty but an identifiable runner remains alive with substantial private memory, the process state deserves investigation rather than being automatically attributed to harmless file caching.
Before reporting a suspected leak, document the Ollama version, model name, operating system, inference backend, request pattern, logs, and memory observations.
➫ Restart Ollama only when necessary
If an identifiable Ollama process continues retaining problematic allocations despite completed requests and successful unload commands, a controlled application or service restart can be a reasonable recovery action.
For a Linux systemd installation:
sudo systemctl restart ollama
On Windows or macOS, quit the application normally and relaunch it.
Restarting interrupts active clients and unloads other resident models. It should not be the default response to a high system-wide memory percentage.
Also, avoid force-killing unrelated processes or manipulating the operating system’s memory caches merely to make a dashboard show more free RAM.
Should You Clear Linux Page Cache to Recover Ollama Memory?
Usually, no.
Linux uses free physical memory productively by caching frequently accessed file data. Flushing this cache indiscriminately can make subsequent application launches and model reloads slower.
It can also hide the original problem without identifying whether a runner is retaining private memory.
There is an important difference between testing a suspected caching effect and adopting cache clearing as a permanent maintenance routine.
If system availability remains healthy and applications are operating normally, cached model pages generally do not require manual intervention.
If memory pressure is genuine, investigate active allocations, container limits, model size, swap activity, and competing workloads first.
For managed servers, a controlled diagnostic procedure is preferable to repeatedly forcing cache reclamation.
How Model Context Size and Parallel Requests Affect Memory
Even when Ollama unloads correctly, an unexpectedly large model allocation during the next session can be mistaken for a memory leak.
One reason is the context window.
The KV cache stores information associated with previously processed tokens. Its memory requirements depend on the architecture, cache representation, context allocation, and inference implementation.
Increasing context length can increase memory requirements, while serving multiple requests concurrently can further increase the amount of memory needed.
Ollama exposes configuration options including OLLAMA_CONTEXT_LENGTH and OLLAMA_NUM_PARALLEL.
For an API request, context length can be configured through options.num_ctx:
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Summarize this short explanation.",
"stream": false,
"options": {
"num_ctx": 4096
},
"keep_alive": 0
}'
The value above is an example setting, not a universal recommendation. Choose a context window appropriate for the actual input and required output.
Reducing the context allocation below what an application needs may cause truncation or reduce the model’s ability to use relevant conversation history.
🤔 Can KV-cache quantization help?
Ollama also documents KV-cache quantization options such as q8_0 and q4_0 for supported configurations using Flash Attention.
These can reduce KV-cache memory requirements, although the quality impact varies by model and workload.
However, changing KV-cache precision is not a direct solution to a model that fails to unload. It addresses memory consumption while the model is running or retained.
For a deeper look at precision trade-offs, see the related Noxoric guide: 🔗 4-Bit vs 8-Bit AI Quantization: Which Should You Use?.
Ollama RAM vs GPU VRAM: Why the Numbers May Disagree
System RAM and GPU VRAM are different resources on computers with dedicated graphics memory.
A model may be loaded primarily onto the GPU while Ollama and other processes continue consuming system RAM.
Ollama’s ollama ps output can help identify whether a model is running on the CPU, GPU, or a combination.
For an NVIDIA GPU, inspect the driver-reported memory allocation using:
nvidia-smi
The command requires a compatible NVIDIA driver and utility installation.
For AMD devices, monitoring depends on the supported driver stack and available tools, such as ROCm utilities on compatible systems.
If the model disappears from Ollama’s running list but VRAM remains occupied, check whether another application or process is using the GPU.
GPU desktop compositors, browsers, games, and other compute workloads can retain allocations independently of Ollama.
On unified-memory architectures, such as Apple silicon, the distinction between system and GPU memory is different. Use the platform’s native memory-pressure indicators rather than directly comparing a unified-memory reading with dedicated GPU VRAM measurements.
Pros and Cons of Immediate Model Unloading
Setting keep_alive to zero can simplify memory management, but it is not automatically the best choice for every workflow.
Immediate Unloading vs. Keeping a Model Resident
✅ Advantages of Immediate Unloading
- Returns model-specific runtime resources sooner.
- Reduces idle model residency.
- Helps free capacity for other applications.
- Can simplify short-lived automation workflows.
- Reduces unnecessary retention between infrequent requests.
❌ Disadvantages of Immediate Unloading
- Later requests must reload the model.
- Cold-start latency may increase.
- Repeated loading creates additional work.
- Runtime and prompt-cache reuse may be reduced.
- Frequent model switching can make interactive use less convenient.
Practical choice: Short or zero retention suits infrequent workloads. A modest idle timeout is often more convenient for repeated interactive requests. Longer retention is appropriate when avoiding reload latency matters more than preserving idle memory capacity.
A Reliable Test for Detecting an Ollama Memory-Release Problem
Before calling an issue a memory leak, run a repeatable test that separates model loading, unloading, caching, and background activity.
Noxoric recommends a measurement-first diagnostic approach: inspect Ollama’s own model state alongside operating-system process and memory information, then change only one relevant setting at a time.
Phase 1: Establish a baseline
Close unrelated memory-intensive applications where practical. Record the Ollama version:
ollama --version
Then check:
ollama ps
Record system available memory, swap usage, and relevant GPU memory utilization using platform-appropriate tools.
Phase 2: Load one model
Start a model that is already installed:
ollama run llama3.2
Send a short prompt and wait until generation finishes.
Run ollama ps again and record the reported model state and memory indicators.
Phase 3: Request unloading
Exit the interactive session, if necessary, and explicitly unload the model:
ollama stop llama3.2
ollama ps
Allow any in-progress cleanup to complete before capturing the next observation.
Phase 4: Compare the correct indicators
✅ Check whether:
- The model has disappeared from Ollama’s running-model list.
- The inference runner has terminated or released its significant allocations.
- System memory availability has recovered sufficiently for normal workloads.
- GPU allocations attributed to the model have been released where applicable.
- No independent client has started another inference request.
Repeat this procedure using the same model, prompt pattern, and configuration if you suspect progressive accumulation.
Persistent growth in a process’s private allocations across equivalent completed cycles is stronger evidence of a leak than a system-wide used-memory percentage remaining high after one run.
Even then, the findings should be described as a suspected leak until the responsible allocation and reproduction conditions are established.
How to Reduce Ollama RAM Usage Without Constantly Restarting It
If your computer has limited memory, prevention is usually more useful than repeatedly stopping the entire Ollama service.
- Use an appropriate keep-alive interval. A shorter timeout reduces the period during which idle models occupy inference resources. Use zero only when repeated reloads are acceptable.
- Check loaded models before launching another. Multiple resident models may compete for limited RAM or VRAM, depending on Ollama’s scheduler configuration and hardware capacity.
- Choose a model that fits the workload. Smaller or more heavily quantized models may require less memory for their weights, but performance and quality depend on the model and hardware.
- Keep context allocations realistic. Oversized context settings increase memory requirements without necessarily helping a short, ordinary task.
- Limit unnecessary concurrency. More parallel requests can increase runtime memory requirements, particularly through additional context state.
- Monitor genuine pressure. Available memory, swap growth, process allocations, and user-visible slowdown provide more meaningful evidence than the total used-memory percentage alone.
- Keep Ollama current. When investigating a reproducible memory-release defect, compare the behavior against a supported current release and consult the project’s issue tracker for related reports.
If memory management also affects response speed, read 🔗 Local LLM Slow First Token? 7 Fixes to Reduce TTFT for a separate explanation of model loading, prompt processing, and first-token latency.
Final Verdict: Diagnose Memory Residency Before Trying to Free RAM
Ollama RAM usage after unloading a model has several possible explanations, and they should not be treated as the same problem.
If the model remains listed in ollama ps, investigate the retention timer, active requests, and unloading configuration. If it disappears but system memory still looks heavily used, inspect file caching and available memory before assuming a fault.
If an identifiable inference runner continues holding substantial private memory, or memory consumption grows persistently across comparable workloads, examine logs, process details, and version-specific reports.
The most effective strategy is straightforward: verify the model state, measure the correct memory indicators, and change the smallest setting that addresses the demonstrated problem.
🚀 Explore more practical AI troubleshooting guides, computing explanations, and free digital tools at Noxoric.



