Skip to content

Flutter for linux doesn't dispose app #136582

Closed
flutter-team-archive/engine
#47684

Description

@AngryMane

Is there an existing issue for this?

Steps to reproduce

#  1. create template flutter application
$ flutter create test_app

# 2. build linux applicatoin
$ flutter build linux

# 3. run linux application with gdb
$ gdb -ex=run build/linux/x64/release/bundle/test_app

# 4. ctrl + c and set break point to `my_application_dispose`
(gdb) b my_application_dispose
(gdb) c

# 5. close app by tapping the cross mark button.  

Expected results

flutter app calls my_application_dispose and gdb catches SIGINT signal at my_application_dispose.

Actual results

flutter app doesn't call my_application_dispose.
But flutter official document expects to call this because it says Make sure to clean it up in my_application_dispose .

I thinks this is resolved by following fix. See the if call g_object_unref movie for the behavior when modified.

$ git diff 
diff --git a/linux/main.cc b/linux/main.cc
index e7c5c54..7b4070d 100644
--- a/linux/main.cc
+++ b/linux/main.cc
@@ -2,5 +2,7 @@
 
 int main(int argc, char** argv) {
   g_autoptr(MyApplication) app = my_application_new();
-  return g_application_run(G_APPLICATION(app), argc, argv);
+  auto ret = g_application_run(G_APPLICATION(app), argc, argv);
+  g_object_unref(app);
+  return ret;
 }

Code sample

It is reproduced in the template app generated by the flutter create command.

Screenshots or Video

Video demonstration for how to reproduce
record.mp4
if call g_object_unref
fixed.mp4

Logs

None

Flutter Doctor output

Doctor output
$ flutter doctor 
Doctor summary (to see all details, run flutter doctor -v):
Could not parse java version from: 

If there is a version please look for an existing bug https://github.com/flutter/flutter/issues/ and if one does not exist file a new issue.
[!] Flutter (Channel stable, 3.13.7, on Ubuntu 22.04.3 LTS 6.2.0-32-generic, locale ja_JP.UTF-8)
    ! Warning: `dart` on your path resolves to /usr/lib/dart/bin/dart, which is not inside your current Flutter SDK checkout at /home/yosuke/development/flutter. Consider adding /home/yosuke/development/flutter/bin to the front of your
      path.
[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    ✗ Could not determine java version
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.74.2)
[✓] Connected device (1 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Oct 16, 2023
  2. huycozy commented on Oct 16, 2023

    @huycozy
    Member

    Thanks for your report. I follow the steps above and can see the same result on the latest Flutter master channel as well.

    flutter doctor -v (stable & master)
    [✓] Flutter (Channel stable, 3.13.7, on Ubuntu 22.04.3 LTS 6.2.0-34-generic, locale en_US.UTF-8)
        • Flutter version 3.13.7 on channel stable at /home/huynq/Documents/Working/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2f708eb839 (7 days ago), 2023-10-09 09:58:08 -0500
        • Engine revision a794cf2681
        • Dart version 3.1.3
        • DevTools version 2.25.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc3)
        • Android SDK at /home/huynq/Android/Sdk/
        • Platform android-33, build-tools 34.0.0-rc3
        • Java binary at: /usr/lib/jvm/java-17-openjdk-amd64/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.8.1+1-Ubuntu-0ubuntu122.04)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Linux toolchain - develop for Linux desktop
        • clang version 10.0.0-4ubuntu1
        • cmake version 3.22.1
        • ninja version 1.10.1
        • pkg-config version 0.29.2
    
    [!] Android Studio (version unknown)
        • Android Studio at /home/huynq/Documents/android-studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        ✗ android-studio-dir = /home/huynq/Documents/android-studio
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
        • Consider removing your android-studio-dir setting by running:
          flutter config --android-studio-dir=
    
    [✓] VS Code (version 1.83.0)
        • VS Code at /usr/share/code
        • Flutter extension version 3.74.0
    
    [✓] Connected device (2 available)
        • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.3 LTS 6.2.0-34-generic
        • Chrome (web)    • chrome • web-javascript • Google Chrome 118.0.5993.70
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    [!] Flutter (Channel master, 3.16.0-11.0.pre.70, on Ubuntu 22.04.3 LTS 6.2.0-34-generic, locale en_US.UTF-8)
        • Flutter version 3.16.0-11.0.pre.70 on channel master at /home/huynq/Documents/Working/flutter_master
        ! Warning: `flutter` on your path resolves to /home/huynq/Documents/Working/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /home/huynq/Documents/Working/flutter_master. Consider adding /home/huynq/Documents/Working/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /home/huynq/Documents/Working/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /home/huynq/Documents/Working/flutter_master. Consider adding /home/huynq/Documents/Working/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 6d5691b4c8 (24 minutes ago), 2023-10-16 03:22:18 -0400
        • Engine revision 12122eac28
        • Dart version 3.3.0 (build 3.3.0-27.0.dev)
        • DevTools version 2.28.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc3)
        • Android SDK at /home/huynq/Android/Sdk/
        • Platform android-33, build-tools 34.0.0-rc3
        • Java binary at: /usr/lib/jvm/java-17-openjdk-amd64/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.8.1+1-Ubuntu-0ubuntu122.04)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Linux toolchain - develop for Linux desktop
        • clang version 10.0.0-4ubuntu1
        • cmake version 3.22.1
        • ninja version 1.10.1
        • pkg-config version 0.29.2
    
    [!] Android Studio (version unknown)
        • Android Studio at /home/huynq/Documents/android-studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        ✗ Unable to determine Android Studio version.
        ✗ android-studio-dir = /home/huynq/Documents/android-studio
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
        • Consider removing your android-studio-dir setting by running:
          flutter config --android-studio-dir=
    
    [✓] VS Code (version 1.83.0)
        • VS Code at /usr/share/code
        • Flutter extension version 3.74.0
    
    [✓] Connected device (2 available)
        • Linux (desktop) • linux  • linux-x64      • Ubuntu 22.04.3 LTS 6.2.0-34-generic
        • Chrome (web)    • chrome • web-javascript • Google Chrome 118.0.5993.70
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 2 categories.
  3. added
    platform-linuxBuilding on or for Linux specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Oct 16, 2023
  4. cbracken commented on Oct 17, 2023

    @cbracken
    Member

    @AngryMane thank you for reporting this issue!

    @robert-ancell does the proposed patch seem reasonable?

  5. robert-ancell commented on Oct 18, 2023

    @robert-ancell
    Contributor

    The patch is doing a double unref - once for the g_autoptr and once for the explicit g_object_unref. So that's not correct, but it indicates that something else has taken a reference to the application and not released it.

  6. robert-ancell commented on Oct 18, 2023

    @robert-ancell
    Contributor

    I confirmed the dispose is not being called. See #136780 for the shutdown signal - this does get called and might be the solution here.

  7. robert-ancell commented on Oct 18, 2023

    @robert-ancell
    Contributor

    I compiled the example app in https://docs.gtk.org/gtk3/getting_started.html#basics - this does call dispose, so there must be some code in our Flutter library that is keeping the application alive.

  8. robert-ancell commented on Oct 18, 2023

    @robert-ancell
    Contributor

    I suspect what might be occurring is we call g_application_quit in the platform plugin when Flutter requests a quit and that doesn't destroy the window objects which hold references to the application. So a solution might be to close all the windows when Flutter quits the application.

  9. robert-ancell commented on Nov 1, 2023

    @robert-ancell
    Contributor

    I've opened a GTK issue on this. We would still need a workaround though in Flutter as an upstream fix would only apply to newer versions of GTK.

  10. AngryMane commented on Nov 1, 2023

    @AngryMane
    Author

    Should I close this issue?
    I think the finalize process I want to execute would work well with your implementation of the shutdown event.

  11. robert-ancell commented on Nov 1, 2023

    @robert-ancell
    Contributor

    No, please keep the issue open - I'm working on a fix in Flutter so the dispose does work. I'd recommend using the shutdown event in your own code as this seems to be the way the GTK developers intended. I think both methods should work, otherwise someone else will likely hit the same issue.

  12. AngryMane commented on Nov 1, 2023

    @AngryMane
    Author

    Understood. I'll leave this issue as is. Thank you for your great work. 😄

  13. added
    r: fixedIssue is closed as already fixed in a newer version
    on Nov 29, 2023
  14. github-actions commented on Dec 13, 2023

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

  15. locked as resolved and limited conversation to collaborators on Dec 13, 2023
  16. added
    team-linuxOwned by the Linux platform team
    and removed on Jun 6, 2024
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

    P2Important issues not at the top of the work lista: desktopRunning on desktopfound in release: 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-linuxBuilding on or for Linux specificallyr: fixedIssue is closed as already fixed in a newer versionteam-linuxOwned by the Linux platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions