Skip to content

Memory Leak in PlaybackCookieJar#307

Open
annrose2277-glitch wants to merge 1 commit into
ProdigyV21:mainfrom
annrose2277-glitch:feat
Open

Memory Leak in PlaybackCookieJar#307
annrose2277-glitch wants to merge 1 commit into
ProdigyV21:mainfrom
annrose2277-glitch:feat

Conversation

@annrose2277-glitch
Copy link
Copy Markdown

During extended playback sessions (3+ hours) with multiple streaming sources, the HTTP layer's PlaybackCookieJar accumulated cookies indefinitely. The underlying cookiesByHost map lacked a mechanism to clean up expired cookies. Over time, this unbounded memory growth caused severe memory pressure, resulting in app slowdowns and eventual crashes on low-memory TV devices.
closes #301

🛠️ Solution
Refactored the PlaybackCookieJar class to enforce strict cookie expiration and map cleanup:

Active Eviction on Save (saveFromResponse): The logic now explicitly filters out expired cookies before saving new ones and merges the valid sets. If a host no longer has any valid cookies after this process, its key is completely removed from the map.

Active Eviction on Load (loadForRequest): The jar now purges any expired cookies from the map before returning the valid list to the HTTP client. Empty host entries are dynamically removed during the load process as well.

📁 Files Modified
app/src/main/kotlin/com/arflix/tv/ui/screens/player/PlayerScreen.kt

✅ Impact & Benefits
Stable Memory Footprint: Eradicates the infinite memory bloat during prolonged viewing sessions.

Improved Performance: Reduces garbage collection (GC) churn, preventing UI stutters and sluggishness on low-RAM TV hardware.

@ProdigyV21
Copy link
Copy Markdown
Owner

Looks good and useful. The cookie cleanup makes sense and should help avoid memory buildup during long playback sessions.

I checked it and both builds pass:

./gradlew :app:compilePlayDebugKotlin
./gradlew :app:compileSideloadDebugKotlin
Only small thing: git diff --check fails because of trailing whitespace on two blank lines in PlayerScreen.kt. Can you clean those two whitespace lines, then this should be safe to merge.

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.

Cookie Jar Memory Leak

2 participants