惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
IT之家
IT之家
S
Secure Thoughts
WordPress大学
WordPress大学
P
Palo Alto Networks Blog
小众软件
小众软件
V
Visual Studio Blog
V
V2EX
人人都是产品经理
人人都是产品经理
AWS News Blog
AWS News Blog
美团技术团队
Jina AI
Jina AI
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
T
Tailwind CSS Blog
腾讯CDC
The Cloudflare Blog
The Hacker News
The Hacker News
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
Lohrmann on Cybersecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
博客园 - 司徒正美
月光博客
月光博客
J
Java Code Geeks
V2EX - 技术
V2EX - 技术
有赞技术团队
有赞技术团队
AI
AI
G
GRAHAM CLULEY
C
Cybersecurity and Infrastructure Security Agency CISA
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
S
Securelist
T
Threat Research - Cisco Blogs
C
Cisco Blogs

WMI

How to Activate MySQL for Multiple Devices - WMI ESLint Flat Config for JS, TS, React, and Prettier - WMI Yarn NPM Registry Configuration - WMI Yarn Guides - WMI Set Up ADB Wireless Debugging on Android: A Full Guide - WMI How to Fill Tax Information on Google Adsense - WMI Migrate ESLint v9 for prettier typescript javascript - WMI PySide6 button click open new window - WMI PySide6 autocomplete input text - WMI Mobile Legends To The Stars Event Clue - WMI [PHP] generate random proxy IP:PORT from CIDR - WMI [PHP] generate big text file for testing purpose - WMI List of Chrome Driver command line arguments - WMI Happy eid mubarak - WMI Install markdown engine on vite ESM typescript - WMI Android Activity lifecycle - WMI OkHttp cookie handling on android (webview supported) - WMI Turn git log history into markdown - WMI is defining screen density can reduce build time ? - WMI
enable automatic memory heap resizing of android studio - WMI
Dimas Lanjaka · 2024-03-02 · via WMI

To limit Android Studio's memory usage, you can modify the studio.vmoptions file. This file contains configuration settings for Android Studio, including memory-related settings. Follow these steps:

  1. Locate the studio.vmoptions file:

    • On Windows, it is usually located in the bin directory of the Android Studio installation directory. For example, C:\Program Files\Android\Android Studio\bin\studio64.exe.vmoptions.
    • On macOS, it is often found in the Contents/bin directory within the application bundle. For example, /Applications/Android Studio.app/Contents/bin/studio.vmoptions.
    • On Linux, it is also typically in the bin directory of the installation. For example, /opt/android-studio/bin/studio64.vmoptions.
  2. Open the studio.vmoptions file in a text editor: Use a text editor like Notepad (on Windows), TextEdit (on macOS), or any code editor of your choice.

  3. Modify the memory settings: Add or modify the following lines to set the maximum heap size (Xmx) and the initial heap size (Xms). Adjust the values according to your system's available memory.

-Xms256m
-Xmx2048m

Example values are used above (-Xms256m for the initial heap size and -Xmx2048m for the maximum heap size). You can increase or decrease these values based on your system's configuration.

  1. Save the changes and restart Android Studio: Save the modifications to the studio.vmoptions file and restart Android Studio for the changes to take effect.

Keep in mind that setting the maximum heap size too high might cause issues if your system doesn't have enough available memory. Adjust the values based on your system's specifications to achieve optimal performance.

Enable automatic memory heap resizing

To add garbage collection options and parallelism while limiting the maximum heap size to 1GB in Android Studio, you can modify the studio.vmoptions file. Here's an example configuration:

Android Studio

# custom Android Studio VM options

# Set the maximum heap size to 1GB
-Xmx1g

# Set the initial heap size
-Xms256m

# Enable parallel garbage collection
-XX:+UseParallelGC

# Enable concurrent garbage collection (for parallel)
-XX:+UseConcMarkSweepGC

# Set the size of the young generation (you may adjust this based on your needs)
-XX:NewSize=512m
-XX:MaxNewSize=512m

# Enable automatic heap resizing
-XX:+UseAdaptiveSizePolicy

Intellij IDEA (Community or Ultimate)

# Use the server JVM, optimized for long-running applications with more aggressive optimizations.
-server 

# Aim to keep GC pause times under 200ms. This affects how the JVM manages memory.
-XX:MaxGCPauseMillis=200

# Trigger garbage collection when 45% of the heap is occupied. Helps manage memory pressure.
-XX:InitiatingHeapOccupancyPercent=45

# Set the ratio of the Eden space (young generation) to the survivor space.
# A ratio of 8 means the Eden space is 8 times larger than a survivor space.
-XX:SurvivorRatio=8

# Allow flushing of compiled code from the code cache to prevent it from running out of memory.
-XX:+UseCodeCacheFlushing

# Reserve 128MB for the code cache, which stores JIT-compiled code.
-XX:ReservedCodeCacheSize=128m

# Enable assertions during runtime for debugging purposes.
-ea

# Disable caching of canonicalized file path strings. 
# This is often useful when working with networked or temporary file systems.
-Dsun.io.useCanonCaches=false


# ===================
# Custom Android Studio VM options
# ===================

# Set the maximum heap size for the JVM to 1GB. Controls the upper limit of memory usage.
-Xmx1g

# Set the initial heap size to 256MB. This is the starting memory allocation.
-Xms256m

# Enable parallel garbage collection to improve throughput by using multiple threads.
-XX:+UseParallelGC

# Enable the concurrent garbage collector, which works alongside the application
# (used in conjunction with parallel GC for balanced performance).
-XX:+UseConcMarkSweepGC

# Set the initial size of the young generation (Eden + survivor spaces) to 512MB.
-XX:NewSize=512m

# Set the maximum size of the young generation to 512MB.
-XX:MaxNewSize=512m

# Enable adaptive resizing of heap spaces to improve performance dynamically based on application behavior.
-XX:+UseAdaptiveSizePolicy

In this configuration:

  • -XX:+UseParallelGC enables the parallel garbage collector.
  • -XX:+UseConcMarkSweepGC enables concurrent garbage collection, which works in conjunction with parallel garbage collection.
  • -XX:NewSize and -XX:MaxNewSize set the size of the young generation, which is part of the heap where new objects are created. Adjust these values based on your requirements.
  • -XX:+UseAdaptiveSizePolicy enables automatic heap resizing based on the application's behavior.

Feel free to adjust these settings based on your system's specifications and the specific needs of your Android Studio projects. Keep in mind that tuning garbage collection settings can be a trial-and-error process, so monitor the performance and adjust as needed. Save the changes, restart Android Studio, and observe the impact on performance.