Memory Leak in PlaybackCookieJar#307
Open
annrose2277-glitch wants to merge 1 commit into
Open
Conversation
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.