24

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?

Md Mahmudul Islam
  • 2,514
  • 4
  • 18
  • 33
  • same issue, i downgraded the flutter version but still no progress – NullByte08 May 24 '20 at 14:21
  • I recently had the same issue and non of the above solution seems to work. I figured out the issue was not flutter related, it was an issue in my code that led to a memory leak. From @Md Mahmudul Islam Answer "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." it clearly implies the issue was with his code on his local machine. – Confidence Yobo Aug 15 '20 at 22:19

8 Answers8

17

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.

Md Mahmudul Islam
  • 2,514
  • 4
  • 18
  • 33
  • I don't know properly. this issue still open see here https://github.com/flutter/flutter/issues/54420. I just think that if I push and pull my project from git repository then I have to get all the dependencies by running **flutter pub get**. After all, my project working fine so far. – Md Mahmudul Islam May 24 '20 at 18:26
  • @MdMahmudulIslam Ah, I just went through that issue on GitHub, there is a broad discussion over and over but didn't get any perfect solution. – Kiran Maniya May 28 '20 at 17:54
2

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

SempaiLeo
  • 334
  • 2
  • 8
1

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

Mimu Saha Tishan
  • 2,402
  • 1
  • 21
  • 40
  • My error log is "Java heap space". I change the gradle.properties under android folder of my flutter project, I change "org.gradle.jvmargs=-Xmx1536M" to "org.gradle.jvmargs=-Xmx2536M", it worked. – leolmq Jan 11 '23 at 06:52
1

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.
Kasun Hasanga
  • 1,626
  • 4
  • 15
  • 35
0

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.

Amr Abd-Alkrim
  • 354
  • 5
  • 12
  • i had this issue. Sometimes the emulator works fine but i am using audioplayers package to play audio but audio is glitchy on the emulator. I tried on the real device but heap space exhausted and my laptop stopped working. – NullByte08 May 24 '20 at 14:32
  • this could be because of latest flutter version 1.17 but i am not sure – NullByte08 May 24 '20 at 14:33
0

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

0

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.

Community
  • 1
  • 1
Prasanth
  • 1
  • 1
0

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.

Ganesh Bhat
  • 246
  • 4
  • 19