Memory leak on page exit
ycuwq opened this issue · comments
This is great library, Thanks for your contribution.
I found a memory leak in samples.
In the basic example when the page exit the val player by rememberManagedExoPlayer()
function will set the player to null, and recompose, And Media
function has Modifier.clickable
. In my case ,it will not be released when fragment are destroyed.
I think your can use playet.release on onDestroy() in your fragments
This player has been released. It triggers recompose when destroy, and it will bring some side effects.
And I solved it:
val player by rememberManagedExoPlayer()
if (player == null) {
return
}
// other code
What kind of side effect does it bring? Null is a valid value for MediaState's player property. And MediaState can do some cleanup stuffs when it is changed. You shouldn't just return here. Otherwise it will cause real memory leak.
In my test demo, it is caused by the fact that the player is set to null multiple times in the destroy of Fragment. When I judge that player==null, the memory leak is solved.
However, it is strange that memory leaks are not captured in compose-media-sample in the same way. Maybe it is caused by my other component associations.