App and MainWindow Destructors Not Being Called #10102
-
When the WinUI3 application exits, the destructors for both the App class and MainWindow are not being called. Is this the expected behavior? You can easily reproduce this issue by adding a destructor to the App class in a new project. struct App : AppT<App>
{
App();
~App()
{
// Destructor
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
As WinUI 3 is currently implemented, the Xaml runtime will never release the last reference it holds to the application object. So yes, it is expected that the destructors for App and any objects held in App will not be called. There is no requirement in Windows for an application to explicitly release all memory used back to Windows as the operating system reclaims all of this memory when the process is exited. |
Beta Was this translation helpful? Give feedback.
As WinUI 3 is currently implemented, the Xaml runtime will never release the last reference it holds to the application object. So yes, it is expected that the destructors for App and any objects held in App will not be called. There is no requirement in Windows for an application to explicitly release all memory used back to Windows as the operating system reclaims all of this memory when the process is exited.
There is no correct way to force App to be destroyed when the application exits, but it is possible to customise the main function and get App to release any objects that it owns.