GVKun编程网logo

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

13

在这篇文章中,我们将为您详细介绍Errorjava.lang.OutOfMemoryError:GCoverheadlimitexceeded的内容。此外,我们还会涉及一些关于Aninternaler

在这篇文章中,我们将为您详细介绍Error java.lang.OutOfMemoryError: GC overhead limit exceeded的内容。此外,我们还会涉及一些关于An internal error occurred during: "Building workspace". GC overhead limit exceeded、Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded、AndroidStudio编译时发生GCOutofMemory错误android studio GC overhead limit exceeded、Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget 急急的知识,以帮助您更全面地了解这个主题。

本文目录一览:

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

执行JUnit测试时,我收到此错误消息:

java.lang.OutOfMemoryError: GC overhead limit exceeded

我知道是什么OutOfMemoryError,但是GC开销限制是什么意思?我该如何解决?

答案1

小编典典

此消息表示由于某种原因,垃圾收集器占用了过多的时间(默认情况下为该进程所有CPU时间的98%),并且每次运行时恢复的内存很少(默认为堆的2%)。

这实际上意味着你的程序停止任何进度,并且一直在忙于仅运行垃圾回收。

为了防止你的应用程序浪费CPU时间而不做任何事情,JVM抛出此错误,Error以便你有机会诊断问题。

我见过这种情况的罕见情况是,某些代码在已经非常受内存限制的环境中创建了大量的临时对象和大量的弱引用对象。

An internal error occurred during:

An internal error occurred during: "Building workspace". GC overhead limit exceeded

An internal error occurred during: "Building workspace".
GC overhead limit exceeded

Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded

Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded

1.在build.gradle添加脚本指定编译堆内存

  • 如果在整个工程中生效,则在build.gradle中增加如下配置:
android {

..............

      dexOptions {

            incremental true

            javaMaxHeapSize "4g"

        }

...............

}
  • 如果只在单元测试的时候生效,则在build.gradle中增加如下配置:
    android {
    
    ..............
    
        testOptions {
    
            android.dexOptions {
    
                incremental true
    
                javaMaxHeapSize "4g"
    
            }
    
        }
    
    ...............
    
    }
    2.添加gradle的配置文件指定堆内存
    也可以在gradle.properties中修改build环境中的jvmargs参数大小:
    在项目根目录新建gradle.properties文件内容为:
  • ## Project-wide Gradle settings.
    #
    # For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    #
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    # Default value: -Xmx10248m -XX:MaxPermSize=256m
    # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    #
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    # org.gradle.parallel=true
    #Mon Jun 13 14:58:46 CST 2016
    org.gradle.daemon=true
    org.gradle.parallel=true
    org.gradle.jvmargs=-Xmx5120m

     

AndroidStudio编译时发生GCOutofMemory错误android studio GC overhead limit exceeded

AndroidStudio编译时发生GCOutofMemory错误android studio GC overhead limit exceeded

在用task的方式编译Android安装包时,出现下面错误

android studio GC overhead limit exceeded

尝试了AndroidStudio重启,ClearCache重启,电脑重启,都没有效果,在打包15个以后,第16个就撑不住了。

看内存占用虽然很高,但是也就只有1G多占用,CPU多了一点。后来查到,应该是和配置有关。按照下面的方式配置,就解决了,而且速度快得一腿。

Step1

在build.gradle文件的android{}中加下面属性配置:

 dexOptions {
        // 4G暂定,也可以修改成别的值
        javaMaxHeapSize "4096M"
    }

Step2

在gradle.properties加入下面配置:

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

重新点击大象编译一下,再执行Task中的buildTask,这样就好多了。

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget 急急

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget 急急

        public View getGroupView(int groupPosition, boolean isExpanded,
                        View convertView, ViewGroup parent) {
                //LayoutInflater 作用是将 layout 的 xml 布局文件实例化为 View 类对象
                Log.i("Test","------------->>>>>> " + (convertView == null));
                if(convertView == null || !(convertView instanceof LinearLayout)){
                        convertView = (LinearLayout) LayoutInflater.from(mContext)
                                        .inflate(R.layout.groupitem, null);
                }
                Log.i("Test", "i am be loaded ----------> groupPosition = " + groupPosition);
                ImageView image = (ImageView) convertView.findViewById(R.id.group_image);
                TextView name = (TextView) convertView.findViewById(R.id.group_name);
                TextView id = (TextView) convertView.findViewById(R.id.group_id);
                TextView currProgram = (TextView) convertView.findViewById(R.id.group_program);
                name.setText(group.get(groupPosition).toString());
                id.setText(String.valueOf(groupPosition));
                currProgram.setText(child.get(groupPosition).get(0).get("name"));
                LinearLayout linear = (LinearLayout) convertView.findViewById(R.id.linearLayout1);
                // 切换到下拉列表
                 if (isExpanded) {
                        image.setImageResource(R.drawable.list_arrow1);
                        linear.setLayoutParams(new LinearLayout.LayoutParams(621,95));
                        //linear.setLayoutParams(new LinearLayout.LayoutParams(640,115));
                        //linear.setBackgroundResource(android.R.color.transparent);
                } else {
                        image.setImageResource(R.drawable.list_arrow0);
                        linear.setLayoutParams(new LinearLayout.LayoutParams(600,87));
                        //linear.setBackgroundResource(R.drawable.selector_0);
                }
                return convertView;

        }

稍后附上错误信息。

今天关于Error java.lang.OutOfMemoryError: GC overhead limit exceeded的讲解已经结束,谢谢您的阅读,如果想了解更多关于An internal error occurred during: "Building workspace". GC overhead limit exceeded、Android Studio编译报错“java.lang.OutOfMemoryError: GC overhead limit exceeded、AndroidStudio编译时发生GCOutofMemory错误android studio GC overhead limit exceeded、Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget 急急的相关知识,请在本站搜索。

本文标签: