# 未处理的异常：OutOfMemoryError：由于内存限制，Isolate 分配失败

- **ID:** `flutter/isolate-memory-limit`
- **领域:** flutter
- **类别:** resource_error
- **错误码:** `OutOfMemoryError`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Dart Isolate 超出了其内存预算（移动端默认约 100MB），通常是由于在 Isolate 内加载大型数据集或无限递归而未正确释放所致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.10 | active | — | — |
| Dart 3.0 | active | — | — |
| Android 12 | active | — | — |
| iOS 15 | active | — | — |

## 解决方案

1. ```
   Process data in chunks: split the large dataset into smaller batches and send each batch to the isolate using `SendPort.send`. Example: `for (var i = 0; i < data.length; i += chunkSize) { isolateSendPort.send(data.sublist(i, min(i+chunkSize, data.length))); }`
   ```
2. ```
   Use streaming isolates with `Isolate.stream` or `ReceivePort` to handle data incrementally, releasing memory after each chunk is processed.
   ```
3. ```
   Optimize data structures: replace large lists with iterators or lazy generators that don't load all data into memory at once.
   ```

## 无效尝试

- **** — The `maxMemory` parameter is not supported on mobile platforms; the limit is enforced by the operating system and cannot be increased by the app. (90% 失败率)
- **** — `Compute` still runs in an isolate with the same memory constraints; passing a large list directly will still cause OOM. (70% 失败率)
- **** — Assertions do not prevent OOM; they only check logical conditions. Memory allocation failures are not caught by assertions. (85% 失败率)
