My Linux system has 4GB memory. After opening Android Studio, it uses less memory even after a few gradle builds. But then it starts accumulating and after some time, I don't have any free memory left.
Initially, my free memory space is around 3GB, which later becomes around 100MB. Is there any way to prevent gradle from caching each build and hogging up memory?
I followed most of the steps here to configure Android Studio to use less memory, but that's not working for me.
You can free up the memory by following these methods.
First, change your studio.vmoptions.
Open studio.vmoptions Help -> Edit Custom VM Options

Add this to the file:
-Xms128m
-Xmx2g
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
Now save the studio.vmoptions file and restart Android Studio.
Second, enable Memory indicator on your studio.
Android Studio -> Preferences -> Appearance & Behaviour
Tick Show Memory Indicator

Now click it to free the memory
I run Xubuntu 20.04 with 4GB RAM via VirtualBox on a MacBook Pro. I have been struggling to find a way to restrict Android Studio's memory usage. Upon googling about "Android Studio memory usage", I see predominantly articles talking about memory usage of an Android app. Apparently a lot of people have trouble with their apps, but the problem I face is the opposite: my app works fine but the IDE I use: Android Studio is having problems. I read some people boasting about powerfulness of the IDE and hence the legitimacy of its high memory usage. I don't buy that. However powerful AS is, I am just using the same small set of functionalities during a period of time when I run in a loop of editing some code and compiling, however, just during this process, its memory usage keeps going up. It's unreasonable. If someone are used to it, I am not.
Through some experiment, I set the following, which seem to help.
$ more studio64.vmoptions
# custom Android Studio VM options, see https://developer.android.com/studio/intro/studio-config.html
-Didea.filewatcher.disabled=true
-Xms64m
-Xmx512m
-XX:MetaspaceSize=64m
-XX:MaxMetaspaceSize=512m
-XX:ReservedCodeCacheSize=128m
-XX:CompressedClassSpaceSize=256m
-XX:+UseStringDeduplication
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
-XX:+HeapDumpOnOutOfMemoryError
-Dfile.encoding=UTF-8
$ more gradle.properties
org.gradle.jvmargs=-Xms64m -Xmx512m -XX:+UseCompressedOops -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With