From 4a236fcf14a15651f0347a8d45f555dc493b3253 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?= Date: Tue, 6 Feb 2024 14:12:47 +0800 Subject: [PATCH] [ios] Fix memory leak in ChildClippingView. --- 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/AUTHORS b/AUTHORS index c018e61980aff..5993e30445856 100644 --- a/AUTHORS +++ b/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/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index f8c878f5639a8..f64a4db8bc284 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -246,6 +246,17 @@ - (void)testChildClippingViewHitTests { 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/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index bf964dbcfa115..6dba0efd89365 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/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/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index ced139de2c9c1..2aa13f5ae09f5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -236,7 +236,7 @@ - (void)dealloc { - (NSMutableArray*)backdropFilterSubviews { if (!_backdropFilterSubviews) { - _backdropFilterSubviews = [[[NSMutableArray alloc] init] retain]; + _backdropFilterSubviews = [[NSMutableArray alloc] init]; } return _backdropFilterSubviews; }