Skip to content

macOS FlutterEngine instances are leaked due to reference cycle #116445

@jason-simmons

Description

@jason-simmons

I was debugging flakes in flutter_desktop_darwin_unittests, and I noticed that the tests were leaking file descriptors and other resources.

Each test allocates a FlutterEngine and then drops its reference. But theseFlutterEngine instances are never deleted.

I traced this to the call to setUpPlatformViewChannel in FlutterEngine.initWithName (https://github.com/flutter/engine/blob/main/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm#L267)

IIUC this is causing the _platformViewsChannel to hold a reference to the FlutterEngine, thus creating a cycle.

There is a TODO implying that there should be another level of indirection between the channel's binaryMessenger and the FlutterEngine reference (https://github.com/flutter/engine/blob/main/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm#L488)

@cbracken

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopengineflutter/engine related. See also e: labels.platform-macBuilding on or for macOS specificallyteam-macosOwned by the macOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions