Skip to content

[BUG] backend.addMediaFile throws OutOfMemoryError #19578

@david-allison

Description

@david-allison

178MB file: https://ankidroid.org/acra/app/1/bug/360462/report/91d6bb58-e609-440f-9bc0-e021667d50b6

  1. We should catch the Error and warn the user
  2. The backend AddMediaFile only accepts a byte array, not a file reference
    • Increasing memory pressure for large files, as it does not support streaming
    • We may wish to define an addMediaFile[ByPath] in Anki-Android-Backend
  3. We should warn users on 100MB+ files and verify they want to continue
java.lang.OutOfMemoryError: Failed to allocate a 178131144 byte allocation with 50331648 free bytes and 163MB until OOM, target footprint 416188144, growth limit 536870912
	at com.google.protobuf.AbstractMessageLite.toByteArray(AbstractMessageLite.java:47)
	at anki.backend.GeneratedBackend.addMediaFile(GeneratedBackend.kt:2883)
	at com.ichi2.anki.libanki.Media.addFile(Media.kt:69)
	at com.ichi2.anki.servicelayer.NoteService.importMediaToDirectory(NoteService.java:144)
	at com.ichi2.anki.NoteEditorFragment$addMediaFileToField$1.invokeSuspend$lambda$0(NoteEditorFragment.kt:2079)
	at com.ichi2.anki.CollectionManager.withCol$lambda$1(CollectionManager.kt:146)
	at com.ichi2.anki.CollectionManager$withQueue$3.invokeSuspend(CollectionManager.kt:128)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:111)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [r0{Cancelling}@e987957, Dispatchers.Main.immediate]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions