Revert "Reland "iOS: Migrate FlutterEngine to ARC" (#55937)" (#55954) There are still a couple closures where on engine shutdown, the last live reference to FlutterEngine may be on a thread other than the platform thread. Specifically, the profiling data capture callback can result in the last live reference to a FlutterEngine being on a profiling thread, resulting in an assertion failure in the destructor of the PlatformViewsController held by FlutterEngine, because PlatformViewsController holds a WeakPtrFactory whose destructor asserts that it be on the platform thread. See: https://github.com/flutter/engine/blob/ad9e4fef451a73427285826455db5fbdde502bd7/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm#L511-L515 Backtrace of such a crash: ``` ================================================================= Main Thread Checker: UI API called on a background thread: -[UIView removeFromSuperview] PID: 46919, TID: 333147, Thread name: FlutterEngine.166.profiler, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 libios_test_flutter.dylib 0x000000014b658aed -[FlutterTextInputPlugin dealloc] + 27 5 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 6 libios_test_flutter.dylib 0x000000014b63df5a -[FlutterEngine .cxx_destruct] + 135 7 libobjc.A.dylib 0x00007ff800035766 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83 8 libobjc.A.dylib 0x00007ff80004ddfc objc_destructInstance + 61 9 CoreFoundation 0x00007ff8004a286b -[NSObject(NSObject) __dealloc_zombie] + 159 10 libios_test_flutter.dylib 0x000000014b635fea -[FlutterEngine dealloc] + 334 11 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 12 libios_test_flutter.dylib 0x000000014b63eda9 _ZNSt3_fl10__function6__funcIZ30-[FlutterEngine startProfiler]E3$_0NS_9allocatorIS2_EEFN7flutter13ProfileSampleEvEEclEv + 69 13 libios_test_flutter.dylib 0x000000014bcd8eaa _ZNSt3_fl10__function6__funcIZNK7flutter16SamplingProfiler16SampleRepeatedlyEN3fml9TimeDeltaEE3$_0NS_9allocatorIS6_EEFvvEEclEv + 40 14 libios_test_flutter.dylib 0x000000014b868786 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 156 15 libios_test_flutter.dylib 0x000000014b86ecca _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26 16 CoreFoundation 0x00007ff8003ea4a5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 17 CoreFoundation 0x00007ff8003ea032 __CFRunLoopDoTimer + 801 18 CoreFoundation 0x00007ff8003e97b6 __CFRunLoopDoTimers + 243 19 CoreFoundation 0x00007ff8003e4028 __CFRunLoopRun + 2108 20 CoreFoundation 0x00007ff8003e3409 CFRunLoopRunSpecific + 557 21 libios_test_flutter.dylib 0x000000014b86ee07 _ZN3fml17MessageLoopDarwin3RunEv + 65 22 libios_test_flutter.dylib 0x000000014b8686a4 _ZN3fml15MessageLoopImpl5DoRunEv + 22 23 libios_test_flutter.dylib 0x000000014b86dce5 _ZNSt3_fl10__function6__funcIZN3fml6ThreadC1ERKNS_8functionIFvRKNS3_12ThreadConfigEEEES7_E3$_0NS_9allocatorISC_EEFvvEEclEv + 135 24 libios_test_flutter.dylib 0x000000014b86da87 _ZZN3fml12ThreadHandleC1EONSt3_fl8functionIFvvEEEEN3$_08__invokeEPv + 27 25 libsystem_pthread.dylib 0x000000010d6a818b _pthread_start + 99 26 libsystem_pthread.dylib 0x000000010d6a3ae3 thread_start + 15 2024-10-18 09:31:27.549111-0700 IosUnitTests[46919:333147] [reports] Main Thread Checker: UI API called on a background thread: -[UIView removeFromSuperview] PID: 46919, TID: 333147, Thread name: FlutterEngine.166.profiler, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 libios_test_flutter.dylib 0x000000014b658aed -[FlutterTextInputPlugin dealloc] + 27 5 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 6 libios_test_flutter.dylib 0x000000014b63df5a -[FlutterEngine .cxx_destruct] + 135 7 libobjc.A.dylib 0x00007ff800035766 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83 8 libobjc.A.dylib 0x00007ff80004ddfc objc_destructInstance + 61 9 CoreFoundation 0x00007ff8004a286b -[NSObject(NSObject) __dealloc_zombie] + 159 10 libios_test_flutter.dylib 0x000000014b635fea -[FlutterEngine dealloc] + 334 11 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 12 libios_test_flutter.dylib 0x000000014b63eda9 _ZNSt3_fl10__function6__funcIZ30-[FlutterEngine startProfiler]E3$_0NS_9allocatorIS2_EEFN7flutter13ProfileSampleEvEEclEv + 69 13 libios_test_flutter.dylib 0x000000014bcd8eaa _ZNSt3_fl10__function6__funcIZNK7flutter16SamplingProfiler16SampleRepeatedlyEN3fml9TimeDeltaEE3$_0NS_9allocatorIS6_EEFvvEEclEv + 40 14 libios_test_flutter.dylib 0x000000014b868786 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 156 15 libios_test_flutter.dylib 0x000000014b86ecca _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26 16 CoreFoundation 0x00007ff8003ea4a5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 17 CoreFoundation 0x00007ff8003ea032 __CFRunLoopDoTimer + 801 18 CoreFoundation 0x00007ff8003e97b6 __CFRunLoopDoTimers + 243 19 CoreFoundation 0x00007ff8003e4028 __CFRunLoopRun + 2108 20 CoreFoundation 0x00007ff8003e3409 CFRunLoopRunSpecific + 557 21 libios_test_flutter.dylib 0x000000014b86ee07 _ZN3fml17MessageLoopDarwin3RunEv + 65 22 libios_test_flutter.dylib 0x000000014b8686a4 _ZN3fml15MessageLoopImpl5DoRunEv + 22 23 libios_test_flutter.dylib 0x000000014b86dce5 _ZNSt3_fl10__function6__funcIZN3fml6ThreadC1ERKNS_8functionIFvRKNS3_12ThreadConfigEEEES7_E3$_0NS_9allocatorISC_EEFvvEEclEv + 135 24 libios_test_flutter.dylib 0x000000014b86da87 _ZZN3fml12ThreadHandleC1EONSt3_fl8functionIFvvEEEEN3$_08__invokeEPv + 27 25 libsystem_pthread.dylib 0x000000010d6a818b _pthread_start + 99 26 libsystem_pthread.dylib 0x000000010d6a3ae3 thread_start + 15 IosUnitTests(47009,0x10ec76240) malloc: enabling scribbling to detect mods to free blocks IosUnitTests(47009) MallocStackLogging: could not tag MSL-related memory as no_footprint, so those pages will be included in process footprint - (null) IosUnitTests(47009) MallocStackLogging: stack logs being written to /private/tmp/stack-logs.47009.1057b6000.IosUnitTests.0o4HgN.index IosUnitTests(47009) MallocStackLogging: recording malloc and VM allocation stacks to disk using standard recorder IosUnitTests(47009) MallocStackLogging: process 46919 no longer exists, stack logs deleted from /tmp/stack-logs.46919.10d1fc000.IosUnitTests.kFionm.index ``` This reverts commit 02fc8a455d0c4b70a70d36e7f4329f5ad706596d. ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I signed the [CLA]. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
The Flutter Engine is a portable runtime for hosting Flutter applications. It implements Flutter's core libraries, including animation and graphics, file and network I/O, accessibility support, plugin architecture, and a Dart runtime and compile toolchain. Most developers will interact with Flutter via the Flutter Framework, which provides a modern, reactive framework, and a rich set of platform, layout and foundation widgets.
If you want to run/contribute to Flutter Web engine, more tooling can be found at felt. This is a tool written to make web engine development experience easy.
If you are new to Flutter, then you will find more general information on the Flutter project, including tutorials and samples, on our Web site at Flutter.dev. For specific information about Flutter's APIs, consider our API reference which can be found at the docs.flutter.dev.
Flutter is a fully open source project, and we welcome contributions. Information on how to get started can be found at our contributor guide.