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
dispose() of Stateful widgets is not called when the App is exited by pressing the backbutton #40940
Why are some widget state dispose() executed when the page is closed, some widget states don't execute dispose, it's really annoying, I want to cry, and the resource release is a problem.
Because there is a lot of code, I can't paste it. I probably tested it myself. This happens when the current page is the last page of the application. Clicking Back will exit the application. At this time, the Widget and the Widget are included. The dispose() of all custom widgets is not executed. I wrote a demo that indicates what I want to express.
This demo has only one page. This page is also the last page of the application. In my actual project, it is the project's home page. Before it has a guide page, the login page is just that they have been closed. The home page is the end of the application. A page, similar to my demo, I don't know why, AppHomeWidget dispose and CustomWidget dispose are not printed.
Reacted by Thomas Burkhart, sj, Ahmad Rifa'i, Tham and Akash P
changed the title [-]dispose() is not call[/-][+]dispose() of Stateful widgets is not called when the App is exited by pressing the backbutton[/+]on Sep 20, 2019
I think this is a big problem. When I want to quit the application, I want to release some resources. Dispose() does not execute. I really don't know how to implement the resource shutdown. I think this problem should be faced by everyone. How to solve it? I want the answer, I am going crazy.
A question is why the state of CustomWidget extends State<StatefulWidget>. I wasn't able to check it but my guess is its the problem. I don't think it is a proper way to make a stateful widget.
Hey you have a sharp eye. It has to be State but I guess that's not really the problem because CustomWidget is a State full Widget. So this should only make problems when you try to access the widget from the state.
But I will give it a try.
I have not closely read this entire thread, but it seems like there are two main concerns here:
Cleaning up resources upon process exit.
Cleaning up resources when the Flutter engine is destroyed (perhaps including Dart VM shutdown), but the process (perhaps including the Dart VM) is still alive.
For the first case, I'm a bit at a loss. Any truly critical resources should just get cleaned up by the OS on process exit. If the resources you want to clean up are things like "send a network request" or "write to the file system," there's really no way to ensure the process can do that before being killed (the device has been powered off, the OS has killed you for memory pressure reasons, a privileged process has killed you with immediate effect, etc.).
For the second case, there are a number of ways to handle this already before you shut down the engine (for example, send a message to the process that would cause it to pump a new and empty widget tree).
I'd find it helpful to hear more about what kind of resources people need to clean up and why the current mechanisms aren't sufficient. For the first case, on platforms where it's well supported (namely desktop), WidgetsBindingObserver.didRequestAppExit can help with the first request (but only to a point, it will not be called e.g. if the power suddenly fails or the process is suddenly killed). For the second case, it's a little harder - but embedding Flutter into another application in general is a little bit harder.
My current situation is that the hybrid development of Flutter is only as part of the app. Click a button from the homepage to enter the Flutter map page. I need to call the dispose() method when closing flutter to tell the AndroidView to destroy the map, but the current mechanism has no way. callback received
This is really hard to work around. I need to have a global registry of resources that I have to manually dispose because of this. It is mentioned in the documentation though, so I guess it's not a bug but correct - but very unexpected - behaviour.
What kind of resources do you have to dispose like that that isn't automatically disposed when the app terminates?
Am 9. Sept. 2024, 19:03 +0100 schrieb Florian Wickert ***@***.***>:
This is really hard to work around. I need to have a global registry of resources that I have to manually dispose because of this. It is mentioned in the documentation though, so I guess it's not a bug but correct - but very unexpected - behaviour.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
But why do you think you have to dispose that thread? Any thread created by the process will terminate when the process dies.
Am 10. Sept. 2024, 07:18 +0100 schrieb Florian Wickert ***@***.***>:
In that particular case it's a thread that does some background rendering for a texture widget.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
Did you look into the NativeFinalizer class if you want to dispose a native Ressource for sure?
Am 10. Sept. 2024, 07:52 +0100 schrieb Florian Wickert ***@***.***>:
In the end it will, but at least on Windows it does so with an abort message box.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
@escamoteur unfortunately, relying on NativeFinalizer is not portable (#132404) and is not triggered on Linux platform.
This needs some cleaning here in Flutter to have a standard way to release native resources on app exit (that is when Dart VM shutdown and before process exits) which is cross-platform and then clearly document this.
Activity
dblokhin commentedon Sep 20, 2019
It would be nice if you attach some problem code.
HQiang commentedon Sep 20, 2019
Because there is a lot of code, I can't paste it. I probably tested it myself. This happens when the current page is the last page of the application. Clicking Back will exit the application. At this time, the Widget and the Widget are included. The dispose() of all custom widgets is not executed. I wrote a demo that indicates what I want to express.
This demo has only one page. This page is also the last page of the application. In my actual project, it is the project's home page. Before it has a guide page, the login page is just that they have been closed. The home page is the end of the application. A page, similar to my demo, I don't know why, AppHomeWidget dispose and CustomWidget dispose are not printed.
HQiang commentedon Sep 20, 2019
In short, when the last page of the application is closed, all widgets' dispose() on this page will not be executed.
escamoteur commentedon Sep 20, 2019
@dblokhin Why the thumbs down if this code reproduces the problem?
escamoteur commentedon Sep 20, 2019
@tvolkert is this by design?
[-]dispose() is not call[/-][+]dispose() of Stateful widgets is not called when the App is exited by pressing the backbutton[/+]dblokhin commentedon Sep 20, 2019
@escamoteur the code was not fenced and highlighted. Currently it's nice. :)
HQiang commentedon Sep 20, 2019
I think this is a big problem. When I want to quit the application, I want to release some resources. Dispose() does not execute. I really don't know how to implement the resource shutdown. I think this problem should be faced by everyone. How to solve it? I want the answer, I am going crazy.
escamoteur commentedon Sep 20, 2019
@HQiang What you can do use https://api.flutter.dev/flutter/widgets/WillPopScope-class.html
for this.
HQiang commentedon Sep 20, 2019
@escamoteur Ok, thank you, rest on the weekend, I will try the company next Monday, thank you again, thank you
dblokhin commentedon Sep 20, 2019
A question is why the state of
CustomWidgetextendsState<StatefulWidget>. I wasn't able to check it but my guess is its the problem. I don't think it is a proper way to make a stateful widget.escamoteur commentedon Sep 20, 2019
Hey you have a sharp eye. It has to be State but I guess that's not really the problem because CustomWidget is a State full Widget. So this should only make problems when you try to access the widget from the state.
But I will give it a try.
71 remaining items
dnfield commentedon Aug 14, 2023
I have not closely read this entire thread, but it seems like there are two main concerns here:
For the first case, I'm a bit at a loss. Any truly critical resources should just get cleaned up by the OS on process exit. If the resources you want to clean up are things like "send a network request" or "write to the file system," there's really no way to ensure the process can do that before being killed (the device has been powered off, the OS has killed you for memory pressure reasons, a privileged process has killed you with immediate effect, etc.).
For the second case, there are a number of ways to handle this already before you shut down the engine (for example, send a message to the process that would cause it to pump a new and empty widget tree).
I'd find it helpful to hear more about what kind of resources people need to clean up and why the current mechanisms aren't sufficient. For the first case, on platforms where it's well supported (namely desktop),
WidgetsBindingObserver.didRequestAppExitcan help with the first request (but only to a point, it will not be called e.g. if the power suddenly fails or the process is suddenly killed). For the second case, it's a little harder - but embedding Flutter into another application in general is a little bit harder.amigo-wangwx commentedon Oct 7, 2023
My current situation is that the hybrid development of Flutter is only as part of the app. Click a button from the homepage to enter the Flutter map page. I need to call the dispose() method when closing flutter to tell the AndroidView to destroy the map, but the current mechanism has no way. callback received
DamnBlack99 commentedon Aug 1, 2024
Hey.
WTS?.
Still there?.
flo-at commentedon Sep 9, 2024
This is really hard to work around. I need to have a global registry of resources that I have to manually dispose because of this. It is mentioned in the documentation though, so I guess it's not a bug but correct - but very unexpected - behaviour.
escamoteur commentedon Sep 9, 2024
flo-at commentedon Sep 10, 2024
In that particular case it's a thread that does some background rendering for a texture widget.
escamoteur commentedon Sep 10, 2024
flo-at commentedon Sep 10, 2024
In the end it will, but at least on Windows it does so with an abort message box.
escamoteur commentedon Sep 10, 2024
flo-at commentedon Sep 10, 2024
In the documentation for
NativeFinalizerit reads:For now I can live with the error. There are workaround to get around this, it's just inconvenient.
ndusart commentedon Sep 12, 2024
@escamoteur unfortunately, relying on
NativeFinalizeris not portable (#132404) and is not triggered on Linux platform.This needs some cleaning here in Flutter to have a standard way to release native resources on app exit (that is when Dart VM shutdown and before process exits) which is cross-platform and then clearly document this.
icodeyou commentedon Feb 22, 2025
Any update on this ? This is a problem for me
fix: dispose widget tree on clean app exit (flutter#40940)
fix: dispose widget tree on clean app exit (flutter#40940)