# CUDA error: out of memory (cudaErrorMemoryAllocation)

**Code:** `CUDA error: out of memory` · **Category:** C/C++ · **Seen on:** C/C++, CUDA

A CUDA allocation failed because the GPU has no free memory for it.

## Meaning

`cudaMalloc` returns `cudaErrorMemoryAllocation` when device memory is exhausted. Other processes, leaks, fragmentation or too-large batches are typical.

## Common causes

- Batch or data too large for the GPU
- Another process holds GPU memory
- Memory leak (missing `cudaFree`)
- Several contexts on one GPU

## Quick fix

1. Check usage with `nvidia-smi`
2. Reduce batch size or use streaming/tiling
3. Free memory with `cudaFree` and check for leaks

## Detailed fix by platform

### Linux

1. `nvidia-smi` and `fuser -v /dev/nvidia*` to find the holders

## How to diagnose

1. **Free** — Memory left?
2. **Processes** — Who uses the GPU?
3. **Leak** — Allocations freed?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/cuda-error-out-of-memory)
