Sdk: dart.exe eating all memory

Created on 21 Jan 2020  ·  47Comments  ·  Source: dart-lang/sdk

When i try to run flutter app in following ide(Android Studio or Visual Studio Code) the dart.exe process is created in the Task Manager(I use windows 10 Pro) and eats up all the RAM(32GB).
I think this is related to the Dart Analysis server, since when I kill the dart process that eats up all the memory in Android Studio displays the message 'Analysis server has terminated'. This process fills RAM at a speed of ~150 MB per second. Note that usually exists several processes dart.exe, but only one of them for some reason eats all the RAM. Please, fix it.

P1 area-analyzer

Most helpful comment

Had the same issue, fixed it by running flutter clean.

All 47 comments

This happens frequently when I checked the "Enable Hot UI" from settings - Languages & Frameworks -> Flutter on Android Studio.

/cc @devoncarew seems like a bug around analysis server memory consumption. I don't know if there is anything users can do to diagnoze?

@inohunk and @masonzhang - can you share the version of the Dart SDK that you're running? From dart --version or flutter --version; thanks.

@inohunk and @masonzhang - in addition to the version of the Dart SDK, it would be useful to get some info from the analyzer diagnostics web page. You can see this info by clicking on the gear icon at the left edge of the "Dart Analysis" tab and selecting "view analyzer diagnostics":
image

Once you've opened the diagnostics page, click on "Contexts" and you should see a page with a tab for each analysis context. make sure that the "Context location" shown for each of the context tabs is a place where you actually expect to see Dart code. (Something that occasionally goes wrong for some users is that they have accidentally configured their IDE in a way that causes it to try to analyze a very large number of files, for example by pointing it to the root of their home directory).

Let us know what you find out and then we can help troubleshoot further.

@stereotype441 thanks a bunch for your feedback. my "flutter --version" command output is as following:

Flutter 1.14.6 • channel beta • https://github.com/flutter/flutter.git
Framework • revision fabeb2a16f (4 weeks ago) • 2020-01-28 07:56:51 -0800
Engine • revision c4229bfbba
Tools • Dart 2.8.0 (build 2.8.0-dev.5.0 fc3af737c7)

I viewed my analyzer diagnostics, and on here are some information for "Context files":

  • Priority files: 1
  • Added files: 49
  • Implicit files: 988 (dart libraries and my plugin libraries)

and nothing special on diagnostics page.

In addition, this happens on my web project with the "Enable Hot UI" from settings checked. I can reproduce this by keeping change code and save.

We found an issue that might be the one causing memory leak when Hot UI is enabled.

This CL https://dart-review.googlesource.com/c/sdk/+/137738 fixes it in Dart SDK, eventually it will percolate to Flutter.

The fix landed as https://github.com/dart-lang/sdk/commit/3cf8c3d4b6130affe668566aecea2ff45c8f721d, and available with Dart SDK 2.8.0-dev.12.0 and 2.8.0-dev.11.0. The current master channel of Flutter uses Dart 2.8.0 (build 2.8.0-dev.12.0 9983424a3c), please try the version of Flutter that has the fix and report if you still experience the memory issue.

@inohunk and @masonzhang , have you had a chance to try and reproduce this with a newer version of Flutter as indicated above?

currently I'm using the beta version. I'll keep you updated once I have tested it. Thanks a lot!

Thanks @masonzhang. Closing for now, but please reopen if you continue to have issues.

I was troubled with this issue since last week, even after upgraded the latest flutter version.
It happens when use flutter run command, but doesn't happen when use flutter build command.
My "flutter --version" command output is as following:

Flutter 1.18.0 • channel dev • https://github.com/flutter/flutter.git
Framework • revision de1e572916 (8 hours ago) • 2020-04-06 16:15:07 -0700
Engine • revision df257e59c2
Tools • Dart 2.8.0 (build 2.8.0-dev.20.0 1210d27678)

Plz fix it...

Update 1: use VS Code to run is OK, but use Android Studio would happen.
Is this more likely a problem of the Android Studio Dart/Flutter plugin?

Update 2: Sadly, today, I use VS Code to run, this issue also happens...

Looking at our internal benchmarks (golem benchmark analysis-server-cold-memory) I see a 75-80% spike in analysis server memory usage at bac08fb3390207849faacc6ce30b8bc42d14032e, which is included in 1210d27678 (the version @yintaibing reported).

@scheglov has been trying to reproduce the memory usage spike locally and hasn't had any luck so far. @sortie can you help?

Same problem here.

[√] Flutter (Channel dev, v1.18.0-dev.5.0, on Microsoft Windows [Version 10.0.18363.720], locale de-DE)
    • Flutter version 1.18.0-dev.5.0 at C:\src\flutter_windows_v1.9.1+hotfix.5-stable\flutter
    • Framework revision 7f56b53de4 (2 days ago), 2020-04-12 12:00:01 -0400
    • Engine revision beb8a7ec48
    • Dart version 2.8.0 (build 2.8.0-dev.20.0 89b0f67261)


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\pschu\AppData\Local\Android\Sdk
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = C:\Users\pschu\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

image

Just a quick update to let users know we are still interested in pursuing this, and have someone who should be able to work on it soon.

An analysis server memory issue was fixed in https://github.com/dart-lang/sdk/commit/838b2eca6a28e4f71faa470a9e2a9befe42c00f9. Does that fix this issue?

We fixed one issue that you have caused higher memory usage than necessary in https://github.com/dart-lang/sdk/commit/838b2eca6a28e4f71faa470a9e2a9befe42c00f9. However because we cannot reproduce this issue per se, we cannot be sure if the fix helps here. Eventually the change will get to Flutter and might help, or not.

what happend ???

I only run https://github.com/flutter/gallery

TIM图片20200425111236
TIM图片20200425091650

Hey @xiaxiayige Dart on Flutter master and dev have been update to 2.9.0-3.0.dev, for me on linux,
maybe that fix mentioned above is in there and it's now worth having another look.

Flutter 1.18.0-9.0.pre.12 • channel master • https://github.com/flutter/flutter.git
Tools • Dart 2.9.0 (build 2.9.0-3.0.dev 94178e920e)

Flutter 1.18.0-8.0.pre • channel dev • https://github.com/flutter/flutter.git
Tools • Dart 2.9.0 (build 2.9.0-3.0.dev b0d35855d8)

Hey @xiaxiayige Dart on Flutter master and dev have been update to 2.9.0-3.0.dev, for me on linux,
maybe that fix mentioned above is in there and it's now worth having another look.

Flutter 1.18.0-9.0.pre.12 • channel master • https://github.com/flutter/flutter.git
Tools • Dart 2.9.0 (build 2.9.0-3.0.dev 94178e9)

Flutter 1.18.0-8.0.pre • channel dev • https://github.com/flutter/flutter.git
Tools • Dart 2.9.0 (build 2.9.0-3.0.dev b0d3585)

Thank you, I have updated, but still the same result

Just now i had this issue in flutter app. And it happened after deleting an asset, from assets folder. Was an error of missing asset, I have replaced in code with another one, but error didn't gone. I restarted project and from that moment dart started to eat all available memmory. I tryed to fix with restarting ide, pc, rebuilding app, but nothing helped.
The only one way was is to delete all project and create new one, keeping lib/ and pubspec.yaml
Flutter is on current master branch

Had the same issue, fixed it by running flutter clean.

Observatory recently added a way to get heap dumps and load them later. So, if you have an issue with continuing heap growth, please make such heap dump, archive it, and share with me. The file will be most probably too big to email it, so consider using Google Drive.

  1. Configure IntelliJ to run DAS with Observatory enabled.
    1.1. Press Shift twice quickly to open the search dialog.
    1.2. Type Registry...
    image

1.3. In the Registry dialog find dart.server.vm.options and add --observe:5000 --disable-service-auth-codes. Note, that with the last option any process on your machine can connect to the Observatory, so remove both options after making the heap dump for better security.
1.4. Restart the Dart Analysis Server.
image

  1. Reproduce the heap growth situation and get the heap dump.
    2.1. Wait until DAS started and done initial analysis.
    2.2. Do things that you observed cause significant growth of consumed memory and observe it using your favorite operating system monitoring tool.
    2.3. Once you see some significant memory usage, connect to Observatory, http://127.0.0.1:5000/. You will see something like this:
    image
    2.4. You need the other isolate, not _cacheCleanUpFunction. It should have a significant number for its heap. For me the whole dart process is reported to have 2.05GB, and the isolate 1.3GB.
    image
    2.5. Click heap snapshot.
    2.6. It will take long time to get the snapshot and analyze it. But eventually you will get something like this:
    image
    2.7. You need the Save button in the top-right corner. Press it, Observatory will download the file with some default name.

  2. Share the file with me: [email protected]
    3.1. Please archive it, it will get about 5 times smaller.
    3.2. I will use this file only to analyze the heap usage, and delete it once done.

Faced same problem today using Android Studio.

image

This memory consuming process is created right after I do "run".

I did https://github.com/dart-lang/sdk/issues/40243#issuecomment-621558656 but it seems to be not a Dart Analysis Server, because in my case I see that Analysis Server is ok and tooks ~200mb.

I tried switching to

  • dev (flutter version 1.18.0-13.0.pre, tools and dart 2.9.0)
  • master (flutter version 1.18.0-14.0.pre.4, tools and dart 2.9.0)
  • stable (flutter version 1.17.0, tools and dart 2.8.1)
    reinstalled flutter SDK but nothing helped.

I had this problem and I solved it with a rather weird workaround.
If you run the App normally the same bug will occur however if you run "profile" button which is located in the right of run button(in android studio) your dart.exe will work fine.
After doing this,run the app normally and you'll see your dart.exe will run fine without becoming too big.
MIne consumes almost 380 Mb of Ram
asd

@jacob314 @johnniwinther It looks like it might be an issue in the flutter process, not sure if something related to compilation to kernel or instrumentation.

WOW my computer is crashing a LOT after flutter 1.17 update. I just figured out that the "dart"process under Task Manager was consuming 10gb of ram!!! (my laptop has only 16)

UPDATE: I did a Flutter Clean and now seems to be fixed.

OMG, dart.exe consumed more than 10gb of my RAM.
I ran the command flutter clean and it seems to be fixed.

Had the same issue, dart.exe consuming around 6-7 Gigs RAM. Doing a flutter clean worked fine.

Update: the issue is back again

I experienced the same issue. a Dart process consumed more than 7gb of my total 8gb memory after i upgraded flutter to version 1.17.0. However as suggested earlier by others, flutter clean seems to fix the issue.
Edit: The issue came back

In the Windows Task Manager, as I recall, one can right-click on the columns and say something like "select columns" -- this gives a check box list that contains an entry like "command" or "command line" or similar. Checking that (and presing ok etc) should give another column with the full command used to create the dart process which would could probably help narrow down which dart process is actually to blame.

I experienced the same issue. a Dart process consumed more than 7gb of my total 8gb memory after i upgraded flutter to version 1.17.0. However as suggested earlier by others, flutter clean seems to fix the issue.

Contrary to my earlier observation that running flutter clean resolved memory consumption issue by dart process. Flutter clean does not offer lasting solution to this problem. The issue came up again, t Anyone with a better solution?

@defemz if you are currently facing this issue, could you try out what I suggested above so we can figure out which exact sub-process it is, using all that memory?

Same issue
any solutions?
image

command line

image
image

@HryhoriiZiahun @defemz @ShivamGoyal1899

To echo @jensjoha's comment, it's most helpful for the team to know exactly which subprocess is consuming memory. If it isn't the dart analyzer we'll need to open other bugs and alert other project teams to these problems.

@HryhoriiZiahun @defemz @ShivamGoyal1899

To echo @jensjoha's comment, it's most helpful for the team to know exactly which subprocess is consuming memory. If it isn't the dart analyzer we'll need to open other bugs and alert other project teams to these problems.

I have pinpointed the dart process causing the unacceptable high RAM consumption. Attached is the process as shown in Windows 10 Task manager. The highlighted entry is the culprit process:
image

and how we can fix this?

Let's fork this issue because it is a different issue.

Filed separate issue https://github.com/dart-lang/sdk/issues/41862 now that we know that it is not analyzer (which is what this issue was originally about).

If anyone can provide reproduction (in https://github.com/dart-lang/sdk/issues/41862) that would be great.

How can i fix this problem.

How can i fix this problem.

@alen252 try flutter clean

How can i fix this problem.

@alen252 try flutter clean

flutter clean is not a permanent solution. With version 1.17.0, build takes much longer and flutter clean mostly solve for current build and not necessarily subsequent builds.

How can i fix this problem.

@alen252 try flutter clean

flutter clean is not a permanent solution. With version 1.17.0, build takes much longer and flutter clean mostly solve for current build and not necessarily subsequent builds.

Yes, Same Issue and yet no permanent solution only going back before 1.17 update 🙁

Had the same issue, fixed it by running flutter clean.

Perfectly worked. I have wasted lot of time to upgrade android and flutter sdk's but noting worked. After i executed, 'flutter clean' which saved my day.

I am on flutter version 1.7.1 on stable channel.
Same story for me. dart.exe consumes full memory and my PC stop responding.
Always i need to flutter clean before every run, and that is not a solution.

I am also facing this issue. dart.exe takes large memory. So, PC is not responding.

I am locking this thread to prevent unrelated "me toos". The work on this problem is tracked in these two issues:

If the problem you have is dart.exe suddenly allocating a lot of memory and forcing you to reboot you can apply this workaround for now.

Was this page helpful?
0 / 5 - 0 ratings