5

I've been trying to update android studio to 2.1 from 2.0 and have run out of idea's. I'm getting a

java.lang.OutOfMemoryError: Java heap space

error. I've tried goggling to find solutions and have tried ones such as these with no joy:

StackOverFlow Answer

Tech-Docs from Google

Here's the full error I'm receiving:

Temp. directory: C:\Users\Aaron\AppData\Local\Temp\
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3236)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at com.intellij.updater.Utils.copyStream(Utils.java:165)
at ie.wombat.jbdiff.JBPatch.bspatch(JBPatch.java:83)
at com.intellij.updater.BaseUpdateAction.applyDiff(BaseUpdateAction.java:112)
at com.intellij.updater.UpdateAction.doApply(UpdateAction.java:44)
at com.intellij.updater.PatchAction.apply(PatchAction.java:184)
at com.intellij.updater.Patch$3.forEach(Patch.java:308)
at com.intellij.updater.Patch.forEach(Patch.java:360)
at com.intellij.updater.Patch.apply(Patch.java:303)
at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:84)
at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:75)
at com.intellij.updater.Runner.doInstall(Runner.java:280)
at com.intellij.updater.Runner.access$000(Runner.java:17)
at com.intellij.updater.Runner$1.execute(Runner.java:246)
at com.intellij.updater.SwingUpdaterUI$5.run(SwingUpdaterUI.java:191)
at java.lang.Thread.run(Thread.java:745)

I've created the .vmoptions file in the correct directory by going to Help > Edit Custom VM Options. The file created was named studio64.exe.vmoptions in case that's of any interest the contents of this file after I edited the one line is:

# custom Android Studio VM options

#
# *DO NOT* modify this file directly. If there is a value that you would like to    override,
# please add it to your user specific configuration file.
#
# See http://tools.android.com/tech-docs/configuration
#
-Xms256m
-Xmx2048m //Edited Line
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-da
-Djna.nosys=true
-Djna.boot.library.path=

-Djna.debug_load=true
-Djna.debug_load.jna=true
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+HeapDumpOnOutOfMemoryError
-Didea.paths.selector=AndroidStudio2.0
-Didea.platform.prefix=AndroidStudio

I had trouble updating from 1.5 to 2.0 before as well and had to do a clean install but that is very tedious for a 18MB patch file.

Finally here's what I think is a range of android related installation folders in what I think is a somewhat random spot. Don't know if that's my doing during the installation or android's:

Installation.

Edit:

This is the notification that I am presented with prior to updating. As you can see it's coming from the stable channel.

Updating.

There is plenty of spare memory available just in case I needed to point that out.

Cheer's for any help.

Community
  • 1
  • 1
COYG
  • 1,538
  • 1
  • 16
  • 31
  • have you tried downloading android studio 2.1 from the stable channel instead of updating from 2.0 to 2.1? – Bhargav May 11 '16 at 04:55
  • @Bhargav Yeah, see edit. – COYG May 11 '16 at 04:58
  • No What I mean is instead of updating? why not download the 2.1 version separetely from the stable channel – Bhargav May 11 '16 at 04:59
  • @COYG can you show me the `idea.properties` file. –  May 11 '16 at 04:59
  • http://tools.android.com/download/studio/builds/2-1 from here just download the android studio, instead of updating – Bhargav May 11 '16 at 05:00
  • @Bhargav - The 2.1 version is over 350MB as mentioned in the question the patch is only 18MB and I'm getting this error for every update. 1.5 > 2 I had to download the whole application. You can't download the 18MB patch on that link provided can I? – COYG May 11 '16 at 05:02
  • @Harshad What directory is that file in? – COYG May 11 '16 at 05:04
  • the increment updates are buggy idk why but they are buggy so I prefer to download the whole thing again. If you search google's android studio issue forum you might find something on this – Bhargav May 11 '16 at 05:04
  • @COYG `in your local config directory` –  May 11 '16 at 05:05
  • Also if you want to try increasing the heap size have a look at this thread http://stackoverflow.com/questions/18723755/android-studio-how-to-increase-allocated-heap-size – Bhargav May 11 '16 at 05:05
  • @Harshad I have a `local.properties` & a `gradle.properties` located in my /user/projects/idea folder. Are they any good to you? – COYG May 11 '16 at 05:09
  • @Bhargav Cheers I'll have a look now. – COYG May 11 '16 at 05:09

3 Answers3

6

I finally resolved the problem, just now.

After almost giving up I went back to the project I was working on and noticed that I was getting 18 instances of the same error when I was compiling an app that was in working order. This error was along the lines of _JAVA_OPTIONS_ -Xmx512m what was strange about this was in the file I created to set custom VM options this value was set at -Xmx2048m.

This led me to think that for some reason this VM option wasn't being recognised possibly because of a studio64.exe.vmoptions file in one of the previous android installation folders. I looked in these folders and did notice another file with this name! I deleted that re-ran the app but was still getting the same error.

This is when I then remembered I created an environment variable over a year ago when I was only starting out on Java and the book I was using to help get to grips with it recommend writing all the programs in a text editor to begin with AND to set environment variables through advanced options in windows. Well that environment variable was still present and lo and behold set at 512m:

1

(Path for anyone else who think they may have done this Control Panel » System » Advanced » Environment Variables)

Deleted this environment variable and to test the water before updating - restarted the app with no errors received this time. Stop running the app, attempted updating to 2.1.1 for the 45th and gladly the final time.

Apologies for not included the missing information in the question but as you can probably appreciate, it could easily slip anyone's mind.

COYG
  • 1,538
  • 1
  • 16
  • 31
3

Based on the stack trace- you just need to customize VM options as below.

-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled 
-XX:+HeapDumpOnOutOfMemoryError

The location you have mentioned is the default location for the windows OS.

You will find Android Studio in these folders by default (unless you have customized it) based on the OS you are using:

in Windows should be in c:\user\yourname.AndroidStudio2.0

in Linux should be in /home/yourname/.AndroidStudio2.0

in Mac should be in ~/Library/Preferences/.AndroidStudio2.0

Also what you can do is-

a. fresh install Android Studio 2.0.

b. do export settings from the previous version-(which will create a .jar file for all the config)

c. import the settings in the newer version.

Community
  • 1
  • 1
Rajeev Dixit
  • 1,533
  • 2
  • 16
  • 25
  • Tried the first step you mentioned, checked the difference in the stack trace from the original one but it was the exact same. Will try a couple of other things before I do the fresh install! – COYG May 11 '16 at 05:48
  • You can also set the JAVA_OPTS environment variable for dealing withjava heap size. Add this as an environment variable as well as you can define a configuration line in the startup.bat file. Add the following line in the startup.bat file. set JAVA_OPTS=-Xms128m -Xmx4096m – Rajeev Dixit May 11 '16 at 06:19
  • Managed to fix it, posted answer to show what was wrong! Cheers for the help. – COYG May 12 '16 at 02:01
0

Delete .gradle file and then try to update to 2.1 it may work