flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.71k stars 27.36k forks source link

VideoPlayer plugin should make sure that resources are released when FlutterView is destroyed #20989

Open nichtverstehen opened 6 years ago

nichtverstehen commented 6 years ago

This is related to https://github.com/flutter/flutter/issues/19206 and https://github.com/flutter/flutter/issues/19358.

VideoPlayer plugin on Android allocates a platform MediaPlayer object for each VideoPlayer plugin in the widget tree. MediaPlayer objects are destroyed when corresponding Flutter widgets go away. But if a whole FlutterView is destroyed, dispose methods don't run, so MediaPlayer instances are not released. This leads to leaks and also crashes (since the player continues to provide frames for non-existent surfaces; internal bug: b/112692333).

IMO, VideoPlayer should rely on normal disposing for the final cleanup and just assert that by the time the view is destroyed all resources are released. This would rely on widgets disposal methods to be called, which is tracked in https://github.com/flutter/flutter/issues/19358.

As a workaround, VideoPlayer should subscribe with a onViewDestroyListener and explicitly release all resources when the owner FlutterView goes away.

TahaTesser commented 4 years ago

Hi @nichtverstehen Given the mentioned PR is merged given your last message I feel safe to close this issue, if you disagree please write in the comments and I will reopen it. Thank you

nichtverstehen commented 4 years ago

The PR comment says:

This is a workaround for widgets not receiving dispose signals when FlutterView is destroyed (flutter/flutter#19358). flutter/flutter#20989 tracks ensuring that resources are released.

So the underlying issue is not fixed. Please keep this open.

vorishirne commented 4 years ago

Pls fix this, its creating huge problems

nixonoftheyear commented 3 years ago

I'm here with the same problem @FlutterIssues

vorishirne commented 3 years ago

we got a workaround here, thinks its a standard way of doing this https://github.com/flutter/flutter/issues/61309