# 警告：检测到 goroutine 泄漏（在 goroutine 5 中）

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

## 根因

由于通道操作阻塞或无限循环而永不退出的 goroutine 会导致内存泄漏。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var wg sync.WaitGroup
wg.Add(1)
go func() {
    defer wg.Done()
    // do work
}()
wg.Wait()
   ```
2. **** (90% 成功率)
   ```
   ctx, cancel := context.WithCancel(context.Background())
go func() {
    select {
    case <-ctx.Done():
        return
    case <-time.After(time.Second):
        // work
    }
}()
cancel()
   ```

## 无效尝试

- **** — GC doesn't collect goroutines; they are not garbage. (100% 失败率)
- **** — Temporary mitigation; eventually memory exhausts. (90% 失败率)
- **** — Leaks accumulate, causing OOM crashes. (80% 失败率)
