Repository navigation
Safari high memory usage #93404
Copy link
Copy link
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listbrowser: safari-macosonly manifests in Safari on macOSonly manifests in Safari on macOSc: performanceRelates to speed or footprint issues (see "perf:" labels)Relates to speed or footprint issues (see "perf:" labels)customer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.found in release: 2.5Found to occur in 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6Found to occur in 2.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onperf: memoryPerformance issues related to memoryPerformance issues related to memoryplatform-webWeb applications specificallyWeb applications specificallyteam-webOwned by Web platform teamOwned by Web platform teamtriaged-webTriaged by Web platform teamTriaged by Web platform team
Description
Details
Target Platform: Web
Target OS version/browser: macOS Big Sur 11.5.2 (20G95) - Safari 14.1.2 (16611.3.10.1.6)
Devices: Mac
Unless I'm looking at the wrong place, it looks like Safari is using a lot of memory for my Flutter app.
In comparison with Chrome, this is not the case.
Left Safari, right Chrome.
If I should be measuring the memory differently, please let me know (I'm not a web developer).
Both are by loading the main page, exact same state.
We are building with
flutter build web --dart-define=SENTRY_RELEASE=$SENTRY_RELEASE -t lib/$FLAVOR_ENTRYPOINT --release --source-maps --web-renderer canvaskit
Logs
Logs
info • The declaration '_createRide' isn't referenced • lib/screens/drivers/detail/drivers_detail_screen.dart:82:8 • unused_element
info • The declaration '_formatBillingAddress' isn't referenced • lib/screens/drivers/detail/tabs/general/driver_details_general_info_tab.dart:270:10 • unused_element
info • Don't import implementation files from another package • lib/screens/signin_signup/views/mobile/signin_link_not_verified_sent_mobile_view.dart:3:8 • implementation_imports
info • Don't import implementation files from another package • lib/screens/signin_signup/views/mobile/signin_link_sent_mobile_view.dart:3:8 • implementation_imports
info • Don't import implementation files from another package • lib/screens/signin_signup/views/mobile/signin_magic_link_sent_mobile_view.dart:3:8 • implementation_imports
info • Don't import implementation files from another package • lib/screens/signin_signup/views/mobile/signin_register_existing_user_linked_mobile_view.dart:3:8 • implementation_imports
info • 'vsync' is deprecated and shouldn't be used. This field is now ignored. This feature was deprecated after v2.2.0-10.1.pre. • lib/screens/signin_signup/views/mobile/signin_signup_mobile_view.dart:56:31 •
deprecated_member_use
info • 'vsync' is deprecated and shouldn't be used. This field is now ignored. This feature was deprecated after v2.2.0-10.1.pre. • lib/screens/signin_signup/views/tablet/signin_signup_tablet_view.dart:76:37 •
deprecated_member_use
8 issues found. (ran in 11.7s)
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.5.2 20G95 darwin-x64, locale en-GB)
• Flutter version 2.5.3 at /Users/glennruysschaert/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/glennruysschaert/Library/Android/sdk
• Platform android-31, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.1, Build version 13A1030d
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.62.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.28.0
[✓] Connected device (3 available)
• Glenn’s iPad (mobile) • 00008101-000D4D112139003A • ios • iOS 15.0.2 19A404
• macOS (desktop) • macos • darwin-x64 • macOS 11.5.2 20G95 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listbrowser: safari-macosonly manifests in Safari on macOSonly manifests in Safari on macOSc: performanceRelates to speed or footprint issues (see "perf:" labels)Relates to speed or footprint issues (see "perf:" labels)customer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.found in release: 2.5Found to occur in 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6Found to occur in 2.6has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onperf: memoryPerformance issues related to memoryPerformance issues related to memoryplatform-webWeb applications specificallyWeb applications specificallyteam-webOwned by Web platform teamOwned by Web platform teamtriaged-webTriaged by Web platform teamTriaged by Web platform team

Activity
mamuseferha commentedon Nov 11, 2021
Hi @vixez
This seems to be more of an issue with your browser than flutter. Can you confirm if the behavior persists when running native web pages and see if there is a significant memory difference?
vixez commentedon Nov 11, 2021
@mamuseferha
I tried various websites (Facebook, Twitter, ..) and Safari does seem to be using more memory than Chrome, but not 10x more than Chrome like in the screenshot. Usually it's 1,5x or 2x more than Chrome.
We tried the Flutter site on various Macs, with different OS and Safari/Chrome versions, and the results are consistent there. The website is always using several times more memory than Chrome. So there must be something that Flutter does which makes Safari take up a lot of resources.
We also got a memory warning from Safari twice on the Flutter website, after which the website started working very slow. This behaviour did not occur on Chrome.
When you watch the memory usage in Chrome it seems like the GC is doing its job well, as the memory goes up when navigating to new routes but also goes back down when popping the routes. On Safari the memory just keeps going up, so maybe something is off with the GC? Just a guess.
mamuseferha commentedon Nov 12, 2021
Hi @vixez I tested this issue on the latest stable and master channel using the default counter app, and memory usage on safari seems to be significantly higher than chrome.
output
safari
chrome
flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6.1 20G224 darwin-x64, locale en-US) • Flutter version 2.5.3 at /Users/flo/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700 • Engine revision d3ea636dc5 • Dart version 2.14.4 [!] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/flo/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 13.0, Build version 13A5212g • CocoaPods version 1.11.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2020.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) [✓] VS Code (version 1.60.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.27.0 [✓] Connected device (4 available) • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • iPhone 12 Pro Max (mobile) • 98CBBFB1-4069-4A28-B7F7-138911ACBE72 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 11.6.1 20G224 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 93.0.4577.63 ! Doctor found issues in 1 category.[✓] Flutter (Channel master, 2.6.0-12.0.pre.701, on macOS 11.6.1 20G224 darwin-x64, locale en-US) • Flutter version 2.6.0-12.0.pre.701 at /Users/flo/fvm/versions/master • Upstream repository https://github.com/flutter/flutter.git • Framework revision 24b9346c9b (7 hours ago), 2021-11-11 16:45:40 -0800 • Engine revision aaacb670af • Dart version 2.15.0 (build 2.15.0-285.0.dev) • DevTools version 2.8.0 [!] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/flo/Library/Android/sdk • Platform android-31, build-tools 31.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [✓] Xcode - develop for iOS and macOS (Xcode 13.0) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2020.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) [✓] VS Code (version 1.60.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.27.0 [✓] Connected device (4 available) • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • iPhone 12 Pro Max (mobile) • 98CBBFB1-4069-4A28-B7F7-138911ACBE72 • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 11.6.1 20G224 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 93.0.4577.63 ! Doctor found issues in 1 category.Thank you
19 remaining items
jezell commentedon Dec 6, 2024
@LuisReyes98 try the solution I linked above. We've been fighting these kinds of issues for years where the app crashes due to running out of canvaskit heap space. Tends to happen a lot more with images data because it uses a lot of heap space.
A few tips that may help people struggling with heap memory problems on the current stable releases:
jezell commentedon Dec 6, 2024
@harryterkelsen @yjbanov I don't think I've filed the RawImage issue, but may be what is causing the Wonderous app to crash. Basic problem is RawImage memory handling assumes the underlying image never changes and then leaks handles because of some bad assumptions in some optimizations made a few years ago. I tracked the details down a while back when we were seeing crashes due to using RawImage. Looks like RawImage is used by Image, and looks like wonderous swaps out images with new images, when clicking around, so might be hitting the same codepath we were having issues with RawImage leaks.
A while back I looked into RawImage to see why it was leaking. Looks like it clones your image handle before it passes it to RenderImage:
flutter/packages/flutter/lib/src/widgets/basic.dart
Line 6131 in 1fb0771
But then RenderImage only disposes the image when it changes if it's a clone of the image that it currently has:
flutter/packages/flutter/lib/src/rendering/image.dart
Line 92 in 1fb0771
Not sure if it's related to wonderous issue, but definitely was causing us trouble...
yjbanov commentedon Dec 6, 2024
A few major things happened since this issue was filed:
Picture.disposealso helps because pictures hold onto images behind-the-scenes too). The standard framework widgets have been updated to take advantage of it. Image data should now be deleted on time, instead of accumulating while the GC is taking its time. The leak tracker is able to track leaked images and report back to the developer.<img>tag instead of wasm codecs. We now upload images into WebGL textures directly, bypassing the wasm memory.@jezell The RawImage issue is concerning. It doesn't look like it would be a Safari-specific issue, but maybe what's happening is that bug jettisons some images back to GC, which means the timing of disposal is subject to browser-specific GC heuristics.
We're also looking into an issue with pictures leaking into GC, which could be related if pictures hold onto image memory behind-the-scenes.
jezell commentedon Dec 6, 2024
@yjbanov Interesting, #153678 sounds like something we've been seeing as well but very hard to repro
yjbanov commentedon Dec 6, 2024
@jezell Have you filed an issue about
RawImage/RenderImage? I'd hate it to get lost in the ocean of github comments (lost in the sea of github issues is better 😄 ).jezell commentedon Dec 6, 2024
@yjbanov hadn't logged it before, but here it is with something that repros a crash on dartpad for me: #159902
koji-1009 commentedon Dec 8, 2024
In Safari, decodeBlobToCkImage(DomBlob blob), CkImageBlobCodec, and HtmlBlobCodec are called in this order. Reading the code,
HtmlBlobCodecis expected to release the blob byrevokeObjectURLindispose()method.However, when I check the flutter/flutter code, it seems that
codec.dispose()is not called. I think the following patch will makerevokeObjectURLto be called. Is this idea correct?#159945
koji-1009 commentedon Dec 17, 2024
For example, in
decodeImageFromListit is easy to see thatui.Codec's dispose is not called.https://github.com/flutter/flutter/blob/3.27.0/packages/flutter/lib/src/painting/image_decoder.dart#L25-L30
I created a PR because it looked like we needed to call
codec.dispose(). #159945Updated
The
BrowserImageDecoderhas an AlarmClock that destroys itself. Therefore,CkBrowserImageDecoderdoes not need to call dispose from outside.On the other hand,
HtmlImageElementCodecdoes not have an AlarmClock to dispose of itself. Therefore,HtmlBlobCodecneeds to call dispose from outside. SincerevokeObjectURLis executed at dispose time, which can lead to memory leaks if not called.These two processes are switched according to the value of
browserSupportsImageDecoder. The implementation must be unified, whether it calls dispose externally or internally.LuisReyes98 commentedon Jan 9, 2025
Update of the use case of the app I work on:
Thanks to the tips given in this thread we manage to figure out what action was causing the crashes in our app.
We use custom made markers with
google_maps_flutter, in which we transform a widget into a markerinternally google scales the images for each platform.
so when we created the marker like this:
The app will crash randomly when adding , updating or removing too many markers at once
So we changed it to be like this:
Declaring the
bitmapScalingtoMapBitmapScaling.nonestabilized the app and managed to make it run properly on Safari using canvas kit.fix: Dispose codec after completing frame creation (#159945)
Allamprabhu11 commentedon Jul 4, 2025
anything update on this issue? we are facing this issue, its been open from 2021
iapicca commentedon Jul 4, 2025
I think the repro code and the info provided by @Rosario9527 are excellent
Garciconx commentedon Dec 10, 2025
Do you have any updates on this? 👀