From e3b318920a022d693b6ed3525f73de6d37f9d7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= <26625149+0xZOne@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:43:37 +0800 Subject: [PATCH] [ios] Fix memory leak in ChildClippingView (flutter/engine#50389) This fixes the memory leak in `ChildClippingView`. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- engine/src/flutter/AUTHORS | 4 +++- .../ios/framework/Source/FlutterPlatformViewsTest.mm | 11 +++++++++++ .../framework/Source/FlutterPlatformViews_Internal.h | 2 ++ .../framework/Source/FlutterPlatformViews_Internal.mm | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/AUTHORS b/engine/src/flutter/AUTHORS index c018e61980..5993e30445 100644 --- a/engine/src/flutter/AUTHORS +++ b/engine/src/flutter/AUTHORS @@ -24,4 +24,6 @@ TheOneWithTheBraid Twin Sun, LLC Qixing Cao LinXunFeng -Amir Panahandeh \ No newline at end of file +Amir Panahandeh +Rulong Chen(陈汝龙) + diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index f8c878f563..f64a4db8bc 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -246,6 +246,17 @@ fml::RefPtr CreateNewThread(const std::string& name) { XCTAssertTrue([childClippingView pointInside:CGPointMake(199, 199) withEvent:nil]); } +- (void)testReleasesBackdropFilterSubviewsOnChildClippingViewDealloc { + __weak NSMutableArray* weakBackdropFilterSubviews = nil; + @autoreleasepool { + ChildClippingView* clipping_view = [[ChildClippingView alloc] initWithFrame:CGRectZero]; + weakBackdropFilterSubviews = clipping_view.backdropFilterSubviews; + XCTAssertNotNil(weakBackdropFilterSubviews); + clipping_view = nil; + } + XCTAssertNil(weakBackdropFilterSubviews); +} + - (void)testApplyBackdropFilter { flutter::FlutterPlatformViewsTestMockPlatformViewDelegate mock_delegate; auto thread_task_runner = CreateNewThread("FlutterPlatformViewsTest"); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index bf964dbcfa..6dba0efd89 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -120,6 +120,8 @@ // filters. - (void)applyBlurBackdropFilters:(NSArray*)filters; +// For testing only. +- (NSMutableArray*)backdropFilterSubviews; @end namespace flutter { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index ced139de2c..2aa13f5ae0 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -236,7 +236,7 @@ static BOOL _preparedOnce = NO; - (NSMutableArray*)backdropFilterSubviews { if (!_backdropFilterSubviews) { - _backdropFilterSubviews = [[[NSMutableArray alloc] init] retain]; + _backdropFilterSubviews = [[NSMutableArray alloc] init]; } return _backdropFilterSubviews; }