oxen-io / session-android

A private messenger for Android.
https://getsession.org
GNU General Public License v3.0
1.73k stars 165 forks source link

[SES-1936] Fix memory leaks #1493

Closed simophin closed 1 month ago

simophin commented 1 month ago

Description

There are a lot of memory leaks in the app, primarily around ConversationActivityV2, basically every conversation page you open it never gets GCed. And soon enough you'll run out of memory.

This is due to a lot of misuse of context.

This PR tries to address these misuses.

simophin commented 1 month ago

There's one instance of leak left that is AudioSlidePlayer, who keeps the context in a global reference. It will leak up to one ConversationActivity I haven't got to check if changing to application context will break the player, will probably include it in a separate PR.

simophin commented 1 month ago

@bemusementpark Please have a look again with the latest change. I've also added the missing animation resume on PathActivity

simophin commented 1 month ago

Hey @bemusementpark @AL-Session , apologies I needed to make additional changes to this PR:

  1. Tidy up the usage of Kotlin Flow in HomeViewModel, now it should be much cleaner on what it's trying to do.
  2. Adds a ContentResolver.observeChanges which unlike app.cash.copper.flow.observeQuery, it cleans up properly
  3. Another leaking place comes from MnemonicCodec.Language where it stores a lambda into a global cache :-(