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
Pigeon: add lifecycle / ability to close down pigeon channels #66994
This is a mix of feature request and a question for pigeon:
Let's say I have a screen in Flutter that requires some data from native code. Data comes over time, so I'm using @FlutterApi. When screen opens, I create Pigeon instance in Flutter and start receiving data.
However, what happens when user closes said screen? From what I can see, Pigeon instances are singletons that never die, potentially causing memory leaks since they reference the UI classes that are not displayed anymore.
Ideally, there would be a way for me to close/dispose the pigeon instance after screen closes. Or is there another pattern that is supposed to be used?
Yea, they are confusing. Channels aren't the things that store the connections. It's all saved on the binary messenger. That's why it is a parameter to creating channels and setting up pigeon.
Thanks for the explanation. However, from what I see, pigeons generated on the dart side do not handle null well (they call the listener even it if it null, spewing errors into the console).
Thanks @matejdro, it would be helpful if you can supply some code where you are seeing the problem. The code using Pigeon and the code generated by Pigeon is helpful. That will make it easier for me to get started when looking into it. I appreciate your help.
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
gaaclarke commentedon Sep 30, 2020
I think what you are looking for is
Api.setup(binaryMessenger, null);, right?matejdro commentedon Oct 2, 2020
Would this work? From what I can see, new message channel is created every time
setupis called. Do those channels share single message handler?matejdro commentedon Oct 2, 2020
Also, from what I see, this does not work on the dart side. Setup method does not check for the null value anywhere.
dispose dart callbacks when activity is closed.preserve_connection_state
dispose dart callbacks when activity is closed
gaaclarke commentedon Oct 2, 2020
Yea, they are confusing. Channels aren't the things that store the connections. It's all saved on the binary messenger. That's why it is a parameter to creating channels and setting up pigeon.
This would clear things out:
{ Channel channel = Channel(binaryMessenger, "foobar"); channel.setHandler(() { print('hello'); }); } { Channel channel = Channel(binaryMessenger, "foobar"); channel.setHandler(null); }matejdro commentedon Oct 2, 2020
Thanks for the explanation. However, from what I see, pigeons generated on the dart side do not handle null well (they call the listener even it if it null, spewing errors into the console).
gaaclarke commentedon Oct 2, 2020
Thanks @matejdro, it would be helpful if you can supply some code where you are seeing the problem. The code using Pigeon and the code generated by Pigeon is helpful. That will make it easier for me to get started when looking into it. I appreciate your help.
matejdro commentedon Oct 2, 2020
Here is an example:
ScanCallbacksinterface (https://github.com/pebble-dev/mobile-app/blob/42c81f4e559d777cd2c9367839add86ae65f9d2d/pigeons/pigeons.dart#L18) generates into this:https://github.com/pebble-dev/mobile-app/blob/42c81f4e559d777cd2c9367839add86ae65f9d2d/lib/infrastructure/pigeons/pigeons.dart#L142
Note that nullability of the
apivariable is never checked, methods are just called blindly. So I can't putnullthere.Keep Pebble connected at all times (#12)
[pigeon] add null handling to FlutterApi.setup()
github-actions commentedon Aug 11, 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.