Flutter: Exhausted heap space, trying to allocate 8589934608 bytes and laptop stops responding

Viewed 11343

When I run my flutter project it was giving me this error below, making my laptop stops responding.

Exhausted heap space, trying to allocate 8589934608 bytes

Screenshot:

enter image description here

I am trying,

  1. flutter clean
  2. Restart my android studio

But Error occur again and again and my laptop sotps responding.

How to resolve this issue?

8 Answers

Some times flutter clean works for me.

But When flutter clean does not work then I apply below technique:

I push my project to git repository(I used Bitbucket) and delete this existing project. Then pull my project from git repository and setup my project. After all my project working as usual.

Try flutter clean along with flutter channel master && flutter upgrade

Thanks @Md Mahmudul Islam. In my case one extra steps solved the issue smoothly.

-Flutter Clean

-Flutter upgrade [upgrade 1.17.2 to 1.17.4]

-Increase Android studio Heap memory :

Program Files->Android->Android Studio->bin->studio64.exe.vmoptions

Open the file and increase the value -Xmx1280m as you want. I changed -Xmx1280 to -Xmx2280

You can also see on bottom right corner, how much memory used in your program by enabling this

File->Settings->Appearance->check 'Show memory indicator'

Note : Try to upgrade Flutter on Latest stable version

This Answer is an Extend of the @Md Mahmudul Islam answer.

1.First try use Flutter Clean

2.If it does not work Delete follow files and Delete application from your Device(Emulator or Real Device)

  • pubspec.lock (not pubspec.yaml)
  • .packages
  • .flutter-plugins-dependencies
  • .flutter-plugins
  • .dart_tool folder eka
  • .git
  • .idea
  • .vscode then Flutter pub get and Run your application.

This issue #54420 is showing a lot these days and its not solved it we are waiting a fix or a work around from the flutter team.

Did you add any gradle dependencies in your build.gradle files lately ? .. If yes try to remove the dependency and test the app again .. Maybe some dependency is making your app heap full

I had the same issue and in my case it was firebase_crashlytics 0.1.3+3 along with its dependencies in the gradle see this github issue comment.

I also had the same problem. This make me restart my computer for 4-5 times. But after when i did flutter-clean it worke

i was also facing the same problem. Tried a lot of things as I got suggestions from different sides. Nothing worked

At last I upgraded the pubspec.yaml file, by simply going to the root file and ran the command

flutter upgrade

It worked

So my suggestion is, using command prompt, go to the location you have saved flutter files, open flutter>>packages>>flutter, the folder where pubspec.yaml file is stored, just run command,

flutter upgrade

It will work, rather it worked for me.

I think this issue is being resolved and will be released in the next update. https://github.com/flutter/flutter/issues/54420

If you are experiencing an issue and would like to stay on stable I believe you can do the following in your flutter SDK checkout to work around the issue:

> git checkout -b patched-stable origin/stable
> git revert f149eec31bfeb5b165cdd507397c657c8c876b56
> del bin\cache\flutter_tools.snapshot
> flutter doctor

You would need to do flutter clean in affected projects once - but after that the issue should not come back.

Related