# RuntimeWarning: More than 20 figures have been opened. Figures created with the pyplot interface (matplotlib.pyplot) are retained until explicitly closed and may consume too much memory.

- **ID:** `python/matplotlib-memory-leak-animation`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Creating many figures in a loop without closing them, leading to memory accumulation.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## Workarounds

1. **Close figures after use with plt.close()** (95% success)
   ```
   for i in range(100): plt.figure(); plt.plot([1,2,3]); plt.close()
   ```
2. **Use plt.close('all') at the end of the loop** (90% success)
   ```
   for i in range(100): plt.figure(); plt.plot([1,2,3]); plt.close('all')
   ```

## Dead Ends

- **Increasing the warning threshold via rcParams** — This silences the warning but does not fix the memory leak. (90% fail)
- **Using plt.ioff() to disable interactive mode** — This only affects display, not memory management. (70% fail)
