From afc4c42763b135eea49b0322c13aac4560989348 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 8 Aug 2022 18:21:35 -0700 Subject: [PATCH] [Windows] Shut down VM on shutdown of last engine All Flutter engines in the same process share a common Dart VM, which is launched with the start of the first engine in the process and should be terminated when the last engine in the process has been deallocated. Formerly, it was not possible to cleanly shut down and restart the VM in a process, but this was resolved in the Dart SDK and a flag exposed in flutter/engine#10652. Since some embedders take advantage of the fact that the VM remains running after engine shutdown, this flag is not enabled by default, however it should be enabled for the Windows embedder, which we control. No tests added since this is not testable via any API to which the Windows embedder has access. The behaviour of this flag is tested in the embedder API tests in `EmbedderTest.VMShutsDownWhenNoEnginesInProcess` in shell/platform/embedder/tests/embedder_unittests.cc. Issue: https://github.com/flutter/flutter/issues/109191 --- shell/platform/windows/flutter_windows_engine.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/windows/flutter_windows_engine.cc b/shell/platform/windows/flutter_windows_engine.cc index 3ed63ae3a3556..a1edfee1c46f3 100644 --- a/shell/platform/windows/flutter_windows_engine.cc +++ b/shell/platform/windows/flutter_windows_engine.cc @@ -254,6 +254,7 @@ bool FlutterWindowsEngine::RunWithEntrypoint(const char* entrypoint) { FlutterProjectArgs args = {}; args.struct_size = sizeof(FlutterProjectArgs); + args.shutdown_dart_vm_when_done = true; args.assets_path = assets_path_string.c_str(); args.icu_data_path = icu_path_string.c_str(); args.command_line_argc = static_cast(argv.size());