# ResourceExhaustedError: Failed to allocate memory for prefetch queue

- **ID:** `tensorflow/resource-exhausted-dataset-prefetch`
- **Domain:** tensorflow
- **Category:** resource_error
- **Error Code:** `PRF`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The tf.data pipeline's prefetch buffer consumes too much memory, often due to large dataset elements or excessive prefetch size.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow 2.14.0 | active | — | — |
| tensorflow 2.16.0 | active | — | — |

## Workarounds

1. **Reduce prefetch buffer size: dataset = dataset.prefetch(buffer_size=tf.data.AUTOTUNE) or set a fixed small value like 1.** (85% success)
   ```
   Reduce prefetch buffer size: dataset = dataset.prefetch(buffer_size=tf.data.AUTOTUNE) or set a fixed small value like 1.
   ```
2. **Use dataset.cache() to store processed elements on disk instead of memory.** (80% success)
   ```
   Use dataset.cache() to store processed elements on disk instead of memory.
   ```
3. **Reduce element size by batching smaller or using lower-resolution images.** (75% success)
   ```
   Reduce element size by batching smaller or using lower-resolution images.
   ```

## Dead Ends

- **** — Increasing overall GPU memory limit doesn't target prefetch buffer specifically. (70% fail)
- **** — Using more CPU cores for mapping can increase memory usage. (50% fail)
