Skip to content

OOM when audio duration too long #49

Description

@liushuai42

Device: Galaxy S24 SM-S921U with Android 14 One UI 6.1

Audio Duration: 2:48:50 (about 3hours)

void audioDecoderTest() async {
  FilePickerResult? result = await FilePicker.pickFiles(
    type: FileType.custom,
    allowedExtensions: ['wav'],
  );
  if (result == null) {
    return;
  }
  final String? chooseFilePath = result.files.first.path;
  if (chooseFilePath == null) {
    toast('No file selected');
    return;
  }

  try {
    final file = File(chooseFilePath);
    if (!await file.exists()) {
      toast('File not exists');
      return;
    }

    showBaseLoading();
    final tempDir = await getTemporaryDirectory();
    String outputPath = path.join(
      tempDir.path,
      '${path.basenameWithoutExtension(chooseFilePath)}.m4a',
    );

    LogUtils.d('Start: $chooseFilePath => $outputPath');
    outputPath = await AudioDecoder.convertToM4a(chooseFilePath, outputPath);
    LogUtils.d('Done: $chooseFilePath => $outputPath');
    await ShareUtil.shareFiles([outputPath], subject: 'm4a audio');
  } catch (e) {
    LogUtils.d('audioDecoderTest failed: $chooseFilePath: $e');
    toast('Exception: $e');
  } finally {
    dismissBaseLoading();
  }
}

E FATAL EXCEPTION: Thread-9
Process: com.halliday.oasis, PID: 9282
java.lang.OutOfMemoryError: Failed to allocate a 1936 byte allocation with 1531696 free bytes and 1495KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
at nl.silversoft.audio_decoder.AudioDecoderPlugin.performM4aConversion(AudioDecoderPlugin.kt:641)
at nl.silversoft.audio_decoder.AudioDecoderPlugin.onMethodCall$lambda$1(AudioDecoderPlugin.kt:86)
at nl.silversoft.audio_decoder.AudioDecoderPlugin.$r8$lambda$aj7LZ3s15fvya7Rb5xVInwT1Ri4(AudioDecoderPlugin.kt:0)
at nl.silversoft.audio_decoder.AudioDecoderPlugin$$ExternalSyntheticLambda29.invoke(D8$$SyntheticClass:0)
at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in reviewIssue is awaiting code review

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions