How to Fix High Memory and CPU Usage by Android Studio and Java

Artem Asoyan
4 min read3 days ago

--

If you’re a developer using a MacBook with an M chip, you might have noticed Android Studio and Java gobbling up your system’s memory and CPU, leaving your machine sluggish. It’s a common pain point, especially when deadlines loom and your MacBook starts to crawl. Don’t worry — I’ve been there, and in this post, I’ll walk you through practical steps to diagnose and fix the issue, so you can get back to coding without the lag.

my 64gb m1 :) no AVD runing

Why This Happens

The M1 chip is a powerhouse, but resource-heavy tools like Android Studio, along with its Java-based processes (think Gradle and the emulator), can push it to its limits. Whether you’ve got 8GB or 16GB of RAM (or 64 GB like me:), these tools can sometimes hog more than their fair share, especially on the M1’s unified memory architecture where CPU and GPU share the same pool. Let’s fix that.

Step-by-Step Solutions

Here’s how to tackle the problem systematically. Follow these steps, and you’ll likely see a big improvement.

1. Check What’s Eating Your Resources

First, let’s confirm Android Studio and Java are the culprits:

  • Open Activity Monitor (hit Cmd + Space, type “Activity Monitor”, and press Enter).
  • Switch to the Memory and CPU tabs.
  • Look for processes like Android Studio, java, or gradle. Are they using a huge chunk of your RAM or spiking your CPU?
  • For reference, M1-M4 MacBooks typically come with 8GB or 32GB of RAM — see how much is left.

If these are the offenders, let’s move on.

2. Restart Android Studio

A quick restart can clear out memory leaks or stuck processes:

  • Quit Android Studio with Cmd + Q or right-click its dock icon and select “Quit.”
  • If it’s frozen, force quit it in Activity Monitor: select the process and click the “X” button.
  • Relaunch it and check if things improve.

3. Tweak Android Studio’s Settings

Let’s optimize how much memory Android Studio and its tools can grab:

  • Lower Memory Allocation:
  • Go to Preferences > Appearance & Behavior > System Settings > Memory Settings.
  • Reduce the IDE max heap size (e.g., drop it from 2048MB to 1280MB).
  • For Gradle, edit (or create) the gradle.properties file in ~/.gradle/ or your project folder. Add:
org.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=512m

# or try this
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.unsafe.configuration-cache=true

This caps Gradle’s memory at 1.5GB.

  • Cut Unnecessary Plugins:
  • Head to Preferences > Plugins.
  • Disable anything you don’t use — like support for languages or frameworks irrelevant to your project.
  • Turn On Power Save Mode:
  • Click File > Power Save Mode. This dials back background tasks, easing the load.

4. Update Your Tools

Using outdated or incompatible versions can cause trouble:

  • Update Android Studio:
  • Check for updates via Android Studio > Check for Updates. Grab the latest M1-optimized version.
  • Use an M-Compatible JDK:
  • Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle.
  • Set the Gradle JDK to something like AdoptOpenJDK 11 or 17 (download an ARM64 version from Adoptium if needed).

5. Lighten the Emulator Load

The Android Emulator can be a resource beast. Here’s how to tame it:

  • Switch to an ARM Image:
  • Open AVD Manager (Tools > Device Manager).
  • Edit your virtual device and pick an arm64-v8a system image — it’s native to the M1 and runs lighter.
  • Or Go Physical:
  • Plug in a real Android device via USB for testing. It skips the emulator entirely.

6. Free Up System Resources

Other apps might be competing for your MacBook’s unified memory:

  • Close memory-hungry apps like Chrome (especially with tons of tabs) or video editors.
  • Check Activity Monitor again — more free RAM means less strain.

7. Kill Rogue Processes

Sometimes Java or Gradle processes linger after you’ve closed Android Studio:

  • In Activity Monitor, search for java, gradle, or adb. Select them and force quit.
  • Or, in Terminal, run:
pkill -f java
pkill -f gradle

8. Watch Your Swap Space

macOS uses swap memory when RAM runs out, but it needs free storage:

  • Ensure you’ve got 20–30GB of free disk space (check in About This Mac > Storage).
  • In Activity Monitor’s Memory tab, look at “Swap Used.” If it’s high, reduce Android Studio’s demands with the steps above.

9. Reinstall Android Studio (If All Else Fails)

A fresh start can wipe out persistent issues:

  • Drag Android Studio from /Applications to the Trash.
rm -rf ~/Library/Application\ Support/Google/AndroidStudio*
rm -rf ~/Library/Preferences/AndroidStudio*

Quick Fix for Instant Relief

Need a fast bailout? Try this:

  • Open Terminal and run:
top -o mem
  • Spot the worst offenders (like java or studio), note their PID (process ID).
  • Kill them with:
kill -9 <PID>

Restart Android Studio.

How to Keep It Smooth Going Forward

Prevention beats firefighting. Here’s how to avoid this mess in the future:

  • Don’t run giant builds or multiple emulators at once.
  • Trim your project by removing unused resources (Refactor > Remove Unused Resources).
  • If you’re on an 8/16GB M1+, ask your employer upgrading to at least 32GB for heavy development — it’s a game-changer.

Wrapping Up

High memory and CPU usage from Android Studio and Java on your MacBook doesn’t have to derail your workflow. With these steps — starting with a quick check in Activity Monitor and moving through optimizations or even a reinstall — you’ll reclaim your system’s performance.

What do you do when your pc out of memory? Share below 👇

--

--

Artem Asoyan
Artem Asoyan

Written by Artem Asoyan

Head Of Mobile, Android Tech/Team Leader, Career mentoring. 12+ years in software development #MobiusConference2023 #PodlodkaAndroidCrew1 #Leetcode (0.4%)

No responses yet