# 致命错误: 运行时: 内存不足

- **ID:** `go/goroutine-not-scheduled`
- **领域:** go
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

无限创建 goroutine，导致系统内存耗尽。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.21 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   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% 成功率)
   ```
   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)
}
   ```

## 无效尝试

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