Repository navigation
Flutter for linux doesn't dispose app #136582
Copy link
Copy link
Closed
flutter-team-archive/engine
#47684Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-linuxBuilding on or for Linux specificallyBuilding on or for Linux specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-linuxOwned by the Linux platform teamOwned by the Linux platform team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16Found to occur in 3.16has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-linuxBuilding on or for Linux specificallyBuilding on or for Linux specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-linuxOwned by the Linux platform teamOwned by the Linux platform team
Activity
huycozy commentedon Oct 16, 2023
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.cbracken commentedon Oct 17, 2023
@AngryMane thank you for reporting this issue!
@robert-ancell does the proposed patch seem reasonable?
robert-ancell commentedon Oct 18, 2023
The patch is doing a double unref - once for the
g_autoptrand once for the explicitg_object_unref. So that's not correct, but it indicates that something else has taken a reference to the application and not released it.robert-ancell commentedon Oct 18, 2023
I confirmed the dispose is not being called. See #136780 for the shutdown signal - this does get called and might be the solution here.
robert-ancell commentedon Oct 18, 2023
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.
robert-ancell commentedon Oct 18, 2023
I suspect what might be occurring is we call
g_application_quitin 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.Implement GApplication:shutdown so a Flutter developer knows where to…
robert-ancell commentedon Nov 1, 2023
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.
AngryMane commentedon Nov 1, 2023
Should I close this issue?
I think the finalize process I want to execute would work well with your implementation of the shutdown event.
robert-ancell commentedon Nov 1, 2023
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.
AngryMane commentedon Nov 1, 2023
Understood. I'll leave this issue as is. Thank you for your great work. 😄
Fix the application not disposing by breaking circular references on …
github-actions commentedon Dec 13, 2023
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.Fix the application not disposing by breaking circular references on …