flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.37k stars 27.55k forks source link

IOSurface didnot dealloc when UIKitView is disposed. #102208

Open xzeroplus opened 2 years ago

xzeroplus commented 2 years ago

Details

I found create UIKitView, when UIKitViews is disposed, IOSurface didnot dealloc, they use lagre memory.

Here is the instruments shapshot with my Demo: I push a lot of page which has an UIKitView, then pop all of them. All UIKitViews is disposed. Even not UIKitView exist, I found the IOSExternalViewEmbedder create many IOSurface, and they not dealloc.

Xnip2022-04-20_18-27-33

Here is my demo: https://github.com/xzeroplus/UIKitView_Demo

Logs

doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.3 21E230 darwin-arm, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.66.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!
darshankawar commented 2 years ago

@xzeroplus I cloned your repo but don't see xcworkspace file in ios folder which we'll need to for automatic signing. Also does this happen in debug mode or in release mode ? Can you also provide steps to replicate this behavior ?

xzeroplus commented 2 years ago

@xzeroplus I cloned your repo but don't see xcworkspace file in ios folder which we'll need to for automatic signing. Also does this happen in debug mode or in release mode ? Can you also provide steps to replicate this behavior ?

  1. run flutter pub get
  2. cd to ios and run pod update

xcworkspace will auto generate when you finish run pod update

xzeroplus commented 2 years ago

@darshankawar This happen both in debug mode and release mode. steps: 1.run my demo 2.click the Increment button in the main page, it will push in a page which has an UIKitView. There is also a Increment button in the new page. Click the Increment button repeatly. (This step will create a lots of UIKitViews.) 3.pop all page.(This step will dispose all the UIKitViews.)

Memory Increment when created UIKitView. But it isnot descend when UIKitViews is disposed. Analyse by instruments ,I found lots of IOSurfaces didnot dealloc.

darshankawar commented 2 years ago

Thanks for the update. Using the code sample provided and running it in debug as well as in release mode on iOS device shows that the memory allocation still remains intact after disposing UIkitView:

Screenshot 2022-04-21 at 6 20 21 PM
stable, master flutter doctor -v ``` [✓] Flutter (Channel stable, 2.10.5, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 2.10.5 at /Users/dhs/documents/fluttersdk/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5464c5bac7 (12 hours ago), 2022-04-18 09:55:37 -0700 • Engine revision 57d3bac3dd • Dart version 2.16.2 • DevTools version 2.9.2 [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [✓] Flutter (Channel master, 2.13.0-0.0.pre.653, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 2.13.0-0.0.pre.653 at /Users/dhs/documents/fluttersdk/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 3fefb2d5eb (15 minutes ago), 2022-04-20 22:34:07 -0700 • Engine revision 4274987f68 • Dart version 2.18.0 (build 2.18.0-37.0.dev) • DevTools version 2.12.2 [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```
xzeroplus commented 2 years ago

Any update on this issue? How to fix it? @darshankawar

chinmaygarde commented 2 years ago

cc @jmagman