Skip to content

fix: stream media downloads to avoid OOM on large files#488

Merged
barrydeen merged 1 commit intomainfrom
fix/media-downloader-oom
Apr 23, 2026
Merged

fix: stream media downloads to avoid OOM on large files#488
barrydeen merged 1 commit intomainfrom
fix/media-downloader-oom

Conversation

@barrydeen
Copy link
Copy Markdown
Owner

Summary

  • MediaDownloader.downloadMedia loaded the entire response body into a ByteArray via response.body.bytes(), which OOMs on large files (e.g. movies) — crash surfaced inside Okio Segment allocation while OkHttp was still buffering HTTP/2 frames.
  • Stream the response body directly into the MediaStore/FileOutputStream with copyTo, keeping only an 8 KB buffer resident.
  • saveImageBytes is unchanged — only used for already-bounded decrypted images.

Test plan

  • Download a small image from a post — still saves to Downloads
  • Download a large video/movie — completes without OOM
  • Download on pre-Q device path still works

@barrydeen barrydeen merged commit 05e1491 into main Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant