Код: Выделить всё
E/DartVM (20411): Exhausted heap space, trying to allocate 131104 bytes.
< /code>
Журнал повторяется много раз, пока приложение не остановится. Вот упрощенная версия моего изолята: < /p>
Future _getSupportedMediaPathsInIsolate(SendPort sendPort) async {
final appDir = await getExternalStorageDirectory();
final files = Directory(appDir!.path).listSync(recursive: true);
final supportedPaths = [];
for (final file in files) {
final path = file.path.toLowerCase();
if (isSupportedImageFile(path) || isSupportedVideoFile(path)) {
supportedPaths.add(file.path);
}
}
sendPort.send(supportedPaths);
}
< /code>
И в основном потоке я поротаю изолят и получаю список путей файла для отображения в пользовательском интерфейсе. I assume it's because the isolate is trying to collect too many media paths and send them all at once.
✅ What I’ve Tried:
[list]
[*]Verified that listSync(recursive: true)[*]Tried increasing heap size (not possible in Flutter AFAIK)
[*]Researched better memory handling in isolates
[/list]
I’m thinking to avoid using Isolate and instead process media using a Dart Stream — yielding one image at a time and displaying it in the UI as Это извлечено. Сканирование больших каталогов и обновление пользовательского интерфейса без проблем с памятью? Многие файлы
Подробнее здесь: https://stackoverflow.com/questions/795 ... fetch-medi
Мобильная версия