The start script <install-path>/android-studio/bin/studio.sh does consult the files as follows to read configurations.


For 64bit systems:

<install-path>/android-studio/bin/studio64.vmoptions
${HOME}/.AndroidStudio<version>/config/studio64.vmoptions
<install-path>/android-studio.vmoptions

For 32bit systems:

<install-path>/android-studio/bin/studio.vmoptions
${HOME}/.AndroidStudio<version>/config/studio.vmoptions
<install-path>/android-studio.vmoptions

Depending on your architecture 32bit vs 64bit and how you did change the heap size setting, you can look through the files mentioned above and alter the Xmx with a text editor of your choice.

Answer from Thomas on askubuntu.com
Discussions

How to solve this fatal exception on Android Studio: Invalid maximum heap size: -Xmx4096m? - Stack Overflow
Now Android Studio wont start. The error shows up as- Invalid maximum heap size: -Xmx4096m # <------ increase this to most of your RAM Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. More on stackoverflow.com
🌐 stackoverflow.com
jvm - Android studio, Invalid maximum heap size - Stack Overflow
I run Android project in Android studio, it appeared error bellow, who can give me solutions resolve problem, thanks!: > com.android.ide.common.internal.LoggedErrorException: Failed to run command:.... Error Code: 1 Output: Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Invalid maximum heap size... More on stackoverflow.com
🌐 stackoverflow.com
July 21, 2016
Android Studio: Invalid maximum heap size: -XmxheapSize, Error:Could not create the Java Virtual Mchine - Stack Overflow
I have recently upgraded my RAM from 2GB to 4GB, I tried to re-install Android studio in my machine through the Ubuntu shell and an this error in the below image: Is there anyone ever encounter this More on stackoverflow.com
🌐 stackoverflow.com
April 13, 2018
Android Studio 1.5.1 - Invalid maximum heap size: -Xmx4g The specified size exceeds the maximum representable size - Stack Overflow
How to resolve the following issue in Android Studio 1.5.1 Version: I tried to increase and decrease the option in dx.bat file like: set defaultXmx=-Xmx512M set defaultXmx=-Xmx1024M set defaultX... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 49880392 › how-to-solve-this-fatal-exception-on-android-studio-invalid-maximum-heap-size
How to solve this fatal exception on Android Studio: Invalid maximum heap size: -Xmx4096m? - Stack Overflow
Now Android Studio wont start. The error shows up as- Invalid maximum heap size: -Xmx4096m # <------ increase this to most of your RAM Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred.
🌐
Stack Overflow
stackoverflow.com › questions › 34737929 › android-studio-1-5-1-invalid-maximum-heap-size-xmx4g-the-specified-size-exce › 34763069
Android Studio 1.5.1 - Invalid maximum heap size: -Xmx4g The specified size exceeds the maximum representable size - Stack Overflow
How to resolve the following issue in Android Studio 1.5.1 Version: I tried to increase and decrease the option in dx.bat file like: set defaultXmx=-Xmx512M set defaultXmx=-Xmx1024M set defaultX...
Find elsewhere
🌐
Reddit
reddit.com › r/androiddev › how to allocate more than 8gb ram for android studio?
r/androiddev on Reddit: How to Allocate More Than 8GB RAM for Android Studio?
September 24, 2024 -

I'm currently using Android Studio with 64GB of available RAM on my system. Despite setting the maximum heap size to 32GB in the studio.vmoptions file, Android Studio only utilizes around 7GB and starts lagging after a while. I find myself needing to restart it every hour during coding sessions. My current configuration is:

-Xms128m
-Xmx32768m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops
-Didea.kotlin.plugin.use.k2=true

While browsing the internet and running other applications simultaneously, only Android Studio lags. Is there a way to force Android Studio to utilize more RAM or improve its performance?

Top answer
1 of 1
29
You probably don't want those settings. Let me break down why: -Xms128m - You're starting off with a tiny heap, almost every Android Studio project will use more than this immediately -Xmx32768m - You're getting into the uncanny valley of memory where going above 32g is going to turn off compressed oops even if you try to keep it on. This is because the JVM cannot keep addressable memory in a compressed form with fewer bytes per address and therefore the memory registers must double in size. I've also never seen an Android Studio project that actually needed that much memory. The max I would go for is 12g on a really beefy machine, you simply don't need such a large heap. Ideally you can keep it around 2-4g which is the sweet spot of performance. -XX:MaxPermSize=1024m <- Unless you're running JDK7 or older this doesn't do anything. Just delete it. Also upgrade to JDK23 and get so many perf wins. -XX:ReservedCodeCacheSize=200m - This value makes the JVM push all 3 codecache memory spaces together into 1, but that's a bit silly since as of JVM 11 there was an optimization to separate them for better perf. Increase to at least 256m, no more than 512m. Kotlin Daemon defaults to 320m. -XX:+UseCompressedOops - this is the default, no need to set it -Didea.kotlin.plugin.use.k2=true - if you're actually using this and not having issues with it, cool. The following are my current settings and I'm generally able to run medium-size projects just fine (50-100 modules and 50k-100k LoC). Most of these settings seem to be defaults in the latest Android Studio canary, I just tweaked a few because my machine has plenty of ram. -Xms512m -Xmx4g -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -XX:+IgnoreUnrecognizedVMOptions -XX:MaxJavaStackTraceDepth=10000 -ea -Dsun.io.useCanonCaches=false -Dsun.java2d.metal=true -Djbr.catch.SIGABRT=true -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Djdk.module.illegalAccess.silent=true -Dkotlinx.coroutines.debug=off -XX:CICompilerCount=2 -XX:ReservedCodeCacheSize=512m -XX:+UnlockDiagnosticVMOptions -XX:TieredOldPercentage=100000 -XX:SoftRefLRUPolicyMSPerMB=50 -Dapple.awt.application.appearance=system If you're working with larger projects than that and you want to see what memory settings you can use I'd bump up heap and reservedcodecachesize. Might also play around with soft references and increase it up to 50.
🌐
Android Developers
developer.android.com › android studio › configure android studio
Configure Android Studio | Android Developers
To do so, follow these steps: Click File > Settings from the menu bar (Android Studio > Preferences on macOS). Click Appearance & Behavior > System Settings > Memory Settings. Figure 2. Configure the maximum amount of RAM in Memory Settings.
🌐
tutorialpedia
tutorialpedia.org › blog › android-studio-how-to-increase-allocated-heap-size
Android Studio: How to Increase Allocated Heap Size to Fix Memory Issues & Prevent Crashes [Step-by-Step Guide] — tutorialpedia.org
By default, Android Studio sets a conservative -Xmx (e.g., 2GB or 4GB), which may be insufficient for large projects or resource-heavy workflows. Increasing the maximum heap size (-Xmx) ensures Android Studio has enough memory to handle demanding ...
🌐
Stack Overflow
stackoverflow.com › questions › 35027798 › error-when-build-apk-invalid-maximum-heap-size-xmx4g
java - Error when build apk, Invalid maximum heap size: -Xmx4g - Stack Overflow
January 27, 2016 - Invalid maximum heap size: -Xmx4g The specified size exceeds the maximum representable size. Error:Execution failed for task ':dexFlavorRelease'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ...
🌐
GitHub
github.com › NativeScript › android-runtime › issues › 758
Invalid maximum heap size: -Xmx16384M · Issue #758 · NativeScript/android
May 9, 2017 - Please refer to the user guide ... Program will exit. Invalid maximum heap size: -Xmx16384M The specified size exceeds the maximum representable size....
Author   NativeScript
🌐
GitHub
github.com › NativeScript › android-runtime › issues › 1182
Invalid maximum heap size: -Xmx16384M Issue #1182 · NativeScript/android · GitHub
October 2, 2018 - From @pushqrdx on October 1, 2018 17:30 Tell us about the problem The gradpe.properties file always contains wrong jvmargs resulting in Invalid maximum heap size error during build. Note that the error occurs with all types of NativeScri...
Author   NativeScript
🌐
Punch Through
punchthrough.com › android-studio
Boost Productivity With 4 Android Studio Tips – Punch Through
May 6, 2025 - Depending on your available RAM, these values could be increased to get better performance out of Android Studio. Xmx specifies the maximum size of the memory allocation pool for JVM. For a PC with 8GB of RAM, -Xmx2G is a good value to start. It’s advisable not to exceed half the maximum size of your system’s RAM size when allocating heap size.