diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 8d7d4f7fef5..262a97a1dc2 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -50,6 +50,10 @@ FLUTTER_EXPORT * A newly initialized engine will not run the `FlutterDartProject` until either * `-runWithEntrypoint:` or `-runWithEntrypoint:libraryURI:` is called. * + * FlutterEngine created with this method will have allowHeadlessExecution set to `YES`. + * This means that the engine will continue to run regardless of whether a `FlutterViewController` + * is attached to it or not, until `-destroyContext:` is called or the process finishes. + * * @param labelPrefix The label prefix used to identify threads for this instance. Should * be unique across FlutterEngine instances, and is used in instrumentation to label * the threads used by this FlutterEngine. @@ -119,6 +123,16 @@ FLUTTER_EXPORT */ - (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)uri; +/** + * Destroy running context for an engine. + * + * This method can be used to force the FlutterEngine object to release all resources. + * After sending this message, the object will be in an unusable state until it is deallocated. + * Accessing properties or sending messages to it will result in undefined behavior or runtime + * errors. + */ +- (void)destroyContext; + /** * Sets the `FlutterViewController` for this instance. The FlutterEngine must be * running (e.g. a successful call to `-runWithEntrypoint:` or `-runWithEntrypoint:libraryURI`) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 10491ffb0c9..6a855650b91 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -149,13 +149,16 @@ - (void)notifyViewControllerDeallocated { if (!_allowHeadlessExecution) { - [self resetChannels]; - - _shell.reset(); - _threadHost.Reset(); + [self destroyContext]; } } +- (void)destroyContext { + [self resetChannels]; + _shell.reset(); + _threadHost.Reset(); +} + - (FlutterViewController*)viewController { if (!_viewController) { return nil;