# fatal error: runtime: out of memory

- **ID:** `go/goroutine-not-scheduled`
- **Domain:** go
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Creating an excessive number of goroutines without limit, exhausting system memory.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.21 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Use a worker pool pattern: 

const maxWorkers = 10
jobs := make(chan int)
var wg sync.WaitGroup
for i := 0; i < maxWorkers; i++ {
    wg.Add(1)
    go func() {
        defer wg.Done()
        for j := range jobs {
            process(j)
        }
    }()
}
// send jobs and close
   ```
2. **** (90% success)
   ```
   Use semaphore channel to limit goroutine count: 

sem := make(chan struct{}, 10)
for _, task := range tasks {
    sem <- struct{}{}
    go func(t task) {
        defer func() { <-sem }()
        process(t)
    }(task)
}
   ```

## Dead Ends

- **** — Temporary fix; doesn't solve the underlying goroutine leak. (90% fail)
- **** — WaitGroup doesn't limit concurrency; it only waits for all to finish. (70% fail)
