-
Notifications
You must be signed in to change notification settings - Fork 27.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak and screen become black when using PlatformView #24145
Comments
I found that the textureEntry created in PlatformViewsController.java(as below code) never call its release. @TargetApi(17)
private void createPlatformView(MethodCall call, Result result) {
...
SurfaceTextureEntry textureEntry = this.mTextureRegistry.createSurfaceTexture();
...
} |
Thanks for the report! flutter/engine#6829 should fix the texture leak. |
Thanks for your fast fix! |
Could this be related to #23181 ? |
I have applied the fix by update flutter to 0.11.7 • channel dev, and i reproduced the black screen issue again. Steps to ReproduceFast scroll up/down the listview that contain AndroidView repeatedly.
And i found that different device have different phenomenon. *On SM G9008V • f8a396e5 • android-arm • Android 6.0 (API 23):app crash and exit. |
I was able to consistently reproduce the issue with the following piece of code: class WebViewCyclerState extends State<WebViewCycler> {
int cycles = 1;
bool running = false;
Timer timer;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Text('Cycled through ${(cycles / 2.0).ceil()} webviews'),
Container(
height: 300,
child: cycles % 2 == 1 ? WebView(initialUrl: 'https://flutter.io',) : null,
),
RaisedButton(
child: Text(running ? 'STOP' : 'RUN'),
onPressed: () {
if (running) {
timer.cancel();
setState(() {
running = false;
});
return;
}
setState(() {
running = true;
});
timer = Timer.periodic(Duration(milliseconds: 250), (Timer t) {
setState(() {
cycles++;
});
});
},
)
],
);
}
} Sent a fix in: flutter/plugins#1221 |
) The reference from the method channel to the webview/maps instance was never cleared on Android, which leaked memory as even after disposing the platform view the view was not released. [flutter/flutter#24145](flutter/flutter#24145)
With flutter/plugins#1221 this is much better, and while I couldn't get it to OOM after that patch, it still looks like there's a slow growth in graphics memory usage, so there might be another leak somewhere. I'm investigating. |
After some more digging, it looks like the leak is not platform view specific but happens whenever we recycle textures (I've observed the leak when doing something similar to the snippet above with the video player). My hypothesis right now is that we are never deleting the textures we allocate at: https://github.com/flutter/engine/blob/733739938bb4f841320e12e32a52c3ba7d69558c/shell/platform/android/android_external_texture_gl.cc#L36 Unfortunately I cannot confirm right now(looks like one of the gclient sync dependencies is super slow right now, and my laptop is not up to date), but my speculative fix would be: I'll follow up tomorrow morning, confirm the fix and if it works submit it. |
On Android we were never deleting the textures allocated for the texture registry, which resulted in a memory leak, see: flutter/flutter#24145
Ok confirmed that with the proposed fix the memory footprint is no longer growing when cycling through textures. |
…7836) On Android we were never deleting the textures allocated for the texture registry, which resulted in a memory leak, see: flutter/flutter#24145
…utter#1221) The reference from the method channel to the webview/maps instance was never cleared on Android, which leaked memory as even after disposing the platform view the view was not released. [flutter/flutter#24145](flutter/flutter#24145)
…utter#1221) The reference from the method channel to the webview/maps instance was never cleared on Android, which leaked memory as even after disposing the platform view the view was not released. [flutter/flutter#24145](flutter/flutter#24145)
…utter#1221) The reference from the method channel to the webview/maps instance was never cleared on Android, which leaked memory as even after disposing the platform view the view was not released. [flutter/flutter#24145](flutter/flutter#24145)
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
result: the screen will become black and nothing will be shown after several times of step2.
And in the log, StrictMode show warning of that surface never release.
Out of memory error log occured at the same time
Logs
The text was updated successfully, but these errors were encountered: