Skip to content

Pigeon: add lifecycle / ability to close down pigeon channels #66994

Closed

Description

@matejdro

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?

Thanks.

@gaaclarke

Activity

  1. gaaclarke commented on Sep 30, 2020

    @gaaclarke
    Member

    I think what you are looking for is Api.setup(binaryMessenger, null);, right?

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 1, 2020
  3. matejdro commented on Oct 2, 2020

    @matejdro
    Author

    Would this work? From what I can see, new message channel is created every time setup is called. Do those channels share single message handler?

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 2, 2020
  5. matejdro commented on Oct 2, 2020

    @matejdro
    Author

    Also, from what I see, this does not work on the dart side. Setup method does not check for the null value anywhere.

  6. gaaclarke commented on Oct 2, 2020

    @gaaclarke
    Member

    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);
    }
  7. matejdro commented on Oct 2, 2020

    @matejdro
    Author

    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).

  8. gaaclarke commented on Oct 2, 2020

    @gaaclarke
    Member

    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.

  9. matejdro commented on Oct 2, 2020

    @matejdro
    Author
  10. added a commit that references this issue on Oct 4, 2020
  11. github-actions commented on Aug 11, 2021

    @github-actions

    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.

  12. locked as resolved and limited conversation to collaborators on Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions