You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FlutterMethodChannel may cause memory leak in iOS #26007
FlutterBinaryMessenger is strongly referenced in FlutterMethodChannel. If the FlutterBinaryMessenger is a FlutterViewController, then this channel should be strongly referenced so that it can work, as the result the FlutterViewController is strongly referenced too. There is no callback for the controller finally releasing so that I can remove this channel.
Is that FlutterBinaryMessenger in FlutterMethodChannel supposed to be weak reference.
Yes, we need to find a good way to make this a weak reference. The way we typically handle it in the embedding (fml::WeakPtr) can't be used because it's C++/Objective C++ that we can't leak out into the public API.
I reopened this because I thought I had a local reproduction. Sitting with @gaaclarke, I'm not actually able to reproduce it anymore.
Can anyone who has been invovled in this provide a simple reproduction for us to work on? If not, I think we can assume this has either been fixed, or it won't result in correct usage of the API.
I may have figured out what this bug is referring to. I've written up a UINavigationController that will push a FlutterViewController onto its stack. When the FlutterViewController is popped it is not deleted immediately. The FlutterEngine and the channel both have retains on the FlutterViewController.
Ideally the inner FlutterViewController should free itself as soon as it pops (rather than its parent, which owns the FlutterEngine) popping. Someone has to call [flutterEngine setViewController:nil] of course but that seems reasonable.
@xster Yes, if we use the FlutterEngine as the binary messenger we don't have to do any of the fiddling with the channel, just calling [flutterEngine setViewController:nil] is sufficient to get the FlutterViewController to dealloc.
After flutter-team-archive/engine#9347 channels still leak, but they won't be holding onto FlutterViewControllers anymore. So, even passing in the FlutterViewController as the binary messenger, you'll be able to dealloc the FlutterViewController (assuming your Engine still isn't referencing it).
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 flutter doctor -v and a minimal reproduction of the issue.
Activity
zoechi commentedon Jan 3, 2019
Please add the output of
flutter doctor -v.wouterhardeman commentedon Jan 3, 2019
I think this will be fixed by: flutter-team-archive/engine#6879
lext-7 commentedon Jan 3, 2019
@wouterhardeman There is no change in the file I mention in this PR.
dnfield commentedon Jan 11, 2019
Yes, we need to find a good way to make this a weak reference. The way we typically handle it in the embedding (fml::WeakPtr) can't be used because it's C++/Objective C++ that we can't leak out into the public API.
18 remaining items
dnfield commentedon Jun 13, 2019
I reopened this because I thought I had a local reproduction. Sitting with @gaaclarke, I'm not actually able to reproduce it anymore.
Can anyone who has been invovled in this provide a simple reproduction for us to work on? If not, I think we can assume this has either been fixed, or it won't result in correct usage of the API.
dnfield commentedon Jun 13, 2019
(What would be ideal is a test case in dev/integration_tests/ios_add2app that fails without this being fixed).
gaaclarke commentedon Jun 14, 2019
I may have figured out what this bug is referring to. I've written up a UINavigationController that will push a FlutterViewController onto its stack. When the FlutterViewController is popped it is not deleted immediately. The FlutterEngine and the channel both have retains on the FlutterViewController.
I was able to force the FlutterViewController to dealloc by clearing out the channel and the engine's view controller: https://gist.github.com/gaaclarke/dd650342fba18ea640c7b3923995cc7d
I'm not sure what we want to do about this yet, but there is the example to get the FlutterViewController to dealloc in the meantime.
xster commentedon Jun 14, 2019
Ideally the inner FlutterViewController should free itself as soon as it pops (rather than its parent, which owns the FlutterEngine) popping. Someone has to call
[flutterEngine setViewController:nil]of course but that seems reasonable.Is this not an issue anymore if our primary doc had people pass the flutterEngine into https://gist.github.com/gaaclarke/dd650342fba18ea640c7b3923995cc7d#file-gistfile1-txt-L35?
gaaclarke commentedon Jun 14, 2019
@xster Yes, if we use the FlutterEngine as the binary messenger we don't have to do any of the fiddling with the channel, just calling
[flutterEngine setViewController:nil]is sufficient to get the FlutterViewController to dealloc.gaaclarke commentedon Jun 19, 2019
After flutter-team-archive/engine#9347 channels still leak, but they won't be holding onto FlutterViewControllers anymore. So, even passing in the FlutterViewController as the binary messenger, you'll be able to dealloc the FlutterViewController (assuming your Engine still isn't referencing it).
gaaclarke commentedon Jun 28, 2019
fixed by flutter-team-archive/engine#9329
github-actions commentedon Aug 28, 2021
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
flutter doctor -vand a minimal reproduction of the issue.