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
A memory leak occurs when using SurfaceView together with AndroidView #118384
Comments
Thanks for the report and details around it. code sample
stable, master flutter doctor -v
|
Any updates on when a fix for this will be released? |
When it will be fixed ? |
Same issue here while integrating cocos2d-x game engine with flutter, destroying and re-adding native views leads to memory leak ( each time 5-10mb jump ). |
This comment was marked as duplicate.
This comment was marked as duplicate.
Mine was related to stale cocos2dx view instance. |
I've modified the code from the repository(https://github.com/add022/flutter_native_view_sample_java) of the report so that it automatically switch the native view's visibility. Please refer to diff.txt. This way, one can use memory profiler to see how the memory grows. Even using TextureView, the memory still grows constantly overtime. I even tried to replace the SurfaceView with a simple TextView to display a few text, I still can see the constant growth. That might be additional leak somewhere. If it's confirmed to happen for general usage, I think the priority should be raised. The following is my simple native view containing a TextView:
|
When it will be fixed ? urgent!! |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
@favazHF I think this one was resolved in https://docs.flutter.dev/release/release-notes/release-notes-3.16.0#android / flutter/engine#43807 |
any update? |
Details
There seems to be a memory leak when using AndroidView together with SurfaceView at native side.
I've created simple app which can demonstrate the issue. It displays AndroidView which could use SurfaceView or TextureView to display native content.
App is able to toggle AndroidView visibility.
The leak occurs when AndroidView is removed from widget tree and then recreated multiple times during app operation.
Sources: https://github.com/add022/flutter_native_view_sample_java
Here is sample screenshot from Profiler when app is using SurfaceView and toggling AndroidView visibility multiple times. Memory constantly growing, GC is also not able to reclaim allocated memory.
I've used SurfaceHolder's callbacks to track surface lifecycle and it seems that surfaceDestroyed() seems to be not called when AndroidView is removed from widget tree. That may be some clue.
On the other side when TextureView is used with the same scenario the leak seems to be not visible, and memory seems to be correclty reclaimed by GC:
I've also examined the lifecycle of TextureView using TextureView.SurfaceTextureListener.
In this case the onSurfaceTextureDestroyed seems to be called every time AndroidView is removed from widget tree.
Issue was oserved on Flutter 3.3.9 and also verified that it still exists in 3.7.0-1.4.pre.
Target Platform: Android
Target OS version/browser: Android 13(and others)
Devices: Samsung S22+(and others)
Logs
Logs
Here is some StrictMode violation which can be observed after GC:
Also following logs about abandoned buffers seems to appear after GC execution:
Flutter doctor:
The text was updated successfully, but these errors were encountered: