Skip to content

PocketCasts keeps OOMing due to background bitmap processing #5317

Description

@passy

Description

Hey Pocketcasterinos,

I'm a big long-term fan and my 1509 days total on the stats screen confirms that.

I run PocketCasts on my "podcast phone", a Nokia G42 with 4GB RAM (4GB ZRAM SWAP) which is clearly on the low and but used to work just fine but for a while now keeps dying in the background when small things happen like a WiFi change that triggers a bunch of background tasks.

I recorded a few Perfetto traces and noticed that there is seemingly a lot of UI work happening in the background causing both CPU and memory pressure.

In PlaybackManager.kt, there is a 1Hz observer that pushes PlaybackState while audio plays. In the player module, this causes eight Composables to run ungated with collectAsState() instead of collectAsStateWithLifecycle() so they keep collecting and recomposing while the host fragment view exists. That means it will keep the RenderThread busy while the app is backgrounded. As long as the app keeps requesting frames, Android's process-state heuristic treats it as foreground, the kernel weighs it against the actually-visible app, and on a 4 GB device PC loses the comparison.

Here's me backgrounding PocketCasts and opening Chrome. It survives for about a minute before it gets killed:

Image

**Is there any particular reason not to use collectAsStateWithLifecycle() in player/view/PlayerHeaderFragment.kt? That would pause the UI updates while the app is backgrounded.

The always-invalidating ChapterProgressBar

player/view/ChapterProgressBar.kt currently has an unguarded invalidation which also causes more re-renders than necessary. If you guarded the invalidate() with an early return

if (field == value) return

and visibility check

if (isAttachedToWindow && isShown) invalidate()

you could save a lot of cycles.

Let me know if this resonates and makes sense. I'd be happy to give this a go myself to try out but didn't want to lose the data on my phone to try it out.

Step-by-step reproduction instructions

  1. Run PocketCasts in the background on low-end phone
  2. Open another apps or sometimes just the keyboard
  3. OOM killer comes after PocketCasts 💀

Screenshots or screen recording

No response

Did you search for existing bug reports?

  • I have searched for existing bug reports.

Device, Operating system, and Pocket Casts app version

Nokia G42, Android 15.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions