Android Throwing OutOfMemoryError"无法分配带有44个空闲字节的164字节分配和44B直到OOM" (递归案例)

时间:2015-07-22 06:24:16

标签: android android-studio out-of-memory

这个应用程序昨天工作,但今天早上开始工作时,我收到以下错误

Throwing OutOfMemoryError "Failed to allocate a 164 byte allocation with 44 free bytes and 44B until OOM" (recursive case)

我不知道发生了什么,或者为什么内存不足。这只是模拟器不能完美运行吗?或者这与我的应用有关吗?

我不知道您需要多少信息。如果您需要更多信息,请告诉我,我会提供。

更新:

我想这与垃圾收集器有关?请参阅下文

Background sticky concurrent mark sweep GC freed 2839(223KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 1603KB/1603KB, paused 31.379ms total 44.794ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 529(29KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 1574KB/2MB, paused 52.919ms total 60.062ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 5551(277KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 4MB/7MB, paused 15.550ms total 85.518ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 20777(1035KB) AllocSpace objects, 0(0B) LOS objects, 36% free, 7MB/11MB, paused 12.467ms total 61.496ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 46653(2MB) AllocSpace objects, 0(0B) LOS objects, 24% free, 12MB/16MB, paused 1.335ms total 138.439ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 27622(1368KB) AllocSpace objects, 0(0B) LOS objects, 20% free, 15MB/19MB, paused 1.459ms total 182.567ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 45635(2MB) AllocSpace objects, 0(0B) LOS objects, 18% free, 17MB/21MB, paused 1.365ms total 157.690ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 22802(1159KB) AllocSpace objects, 0(0B) LOS objects, 16% free, 20MB/24MB, paused 1.211ms total 180.755ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 14475(641KB) AllocSpace objects, 0(0B) LOS objects, 2% free, 23MB/24MB, paused 1.106ms total 122.625ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 27477(1338KB) AllocSpace objects, 0(0B) LOS objects, 14% free, 23MB/27MB, paused 1.511ms total 147.653ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 37938(1865KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 25MB/29MB, paused 1.253ms total 178.420ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 23214(1147KB) AllocSpace objects, 0(0B) LOS objects, 12% free, 28MB/32MB, paused 3.789ms total 190.825ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 36253(1773KB) AllocSpace objects, 0(0B) LOS objects, 11% free, 31MB/35MB, paused 1.085ms total 227.583ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 13949(616KB) AllocSpace objects, 0(0B) LOS objects, 2% free, 34MB/35MB, paused 665us total 175.362ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 40440(2000KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 33MB/37MB, paused 2.158ms total 311.515ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 13956(617KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 36MB/37MB, paused 42.198ms total 81.851ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 33376(1624KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 36MB/40MB, paused 1.211ms total 322.374ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 4052(174KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 40MB/40MB, paused 1.245ms total 105.928ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 38452(1891KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 39MB/43MB, paused 1.212ms total 282.053ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 15083(667KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 42MB/43MB, paused 1.006ms total 134.368ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 33122(1609KB) AllocSpace objects, 0(0B) LOS objects, 8% free, 42MB/46MB, paused 1.759ms total 685.984ms
2431-2443/com.example.christian.welldanaapp W/art﹕ Suspending all threads took: 21.776ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 2898(122KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 46MB/46MB, paused 23.019ms total 71.640ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 29828(1485KB) AllocSpace objects, 0(0B) LOS objects, 8% free, 45MB/49MB, paused 1.250ms total 194.222ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 37388(1848KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 48MB/52MB, paused 1.243ms total 332.837ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 31151(1528KB) AllocSpace objects, 0(0B) LOS objects, 7% free, 51MB/55MB, paused 1.446ms total 336.916ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 12755(563KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 54MB/55MB, paused 14.512ms total 48.881ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 40981(2014KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 53MB/57MB, paused 1.288ms total 402.576ms
2431-2443/com.example.christian.welldanaapp W/art﹕ Suspending all threads took: 18.769ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background partial concurrent mark sweep GC freed 32370(1572KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 56MB/60MB, paused 20.234ms total 387.007ms
2431-2443/com.example.christian.welldanaapp W/art﹕ Suspending all threads took: 10.568ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Background sticky concurrent mark sweep GC freed 12559(558KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 59MB/60MB, paused 11.757ms total 42.520ms
2431-2443/com.example.christian.welldanaapp I/art﹕ Clamp target GC heap from 64MB to 64MB

实际红色文字

07-22 06:39:06.976    2431-2431/com.example.christian.welldanaapp E/AndroidRuntime﹕ Error reporting crash
java.lang.OutOfMemoryError: Failed to allocate a 458 byte allocation with 1613776 free bytes and 1575KB until OOM; failed due to fragmentation (required continguous free 32768 bytes for a new buffer where largest contiguous free 4096 bytes)
        at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
        at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:146)
        at java.lang.StringBuilder.append(StringBuilder.java:216)
        at java.lang.Throwable.toString(Throwable.java:360)
        at java.lang.Throwable.printStackTrace(Throwable.java:315)
        at java.lang.Throwable.printStackTrace(Throwable.java:300)
        at android.util.Log.getStackTraceString(Log.java:335)
        at com.android.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:59)
        at com.android.internal.os.RuntimeInit.access$200(RuntimeInit.java:43)
        at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:85)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

编辑:JAVA代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    ChangeLanguage("dk");
    SetListeners();
}

//Changes the language depending on the button pressed
private void ChangeLanguage(String language){
    Locale locale = new Locale(language);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getResources().updateConfiguration(config,getResources().getDisplayMetrics());
    setContentView(R.layout.activity_main);
    RestartActivity();
}

//Restarts the activity after changing the languagse
private void RestartActivity(){
    Intent intent = getIntent();
    finish();
    startActivity(intent);
}

5 个答案:

答案 0 :(得分:5)

当您在项目中使用 REALLY BIG 图像时,通常会发生此类错误。尝试缩小图像尺寸,这个错误就解决了。

如果您不使用某些专业图像编辑软件(如Photoshop或Illustrator),则可以使用内置图像查看器执行此简单任务。

在Mac上,您可以使用预览应用程序缩小图像尺寸。

  • 使用预览打开图像(只需双击图像,预览是默认应用程序)。
  • 选择标记工具栏(看起来像公文包)。
  • 点击“调整大小”按钮(看起来像一个正方形,两个箭头对面的角落)。
  • 输入所需的宽度和高度。
  • 点击确定,你就完成了=)

**我没有使用电脑,所以我无法解释如何解决这个问题,但它也应该非常简单。

我希望它有助于某人...

答案 1 :(得分:4)

尝试这可以帮助您在清单文件中添加此标记。

<application android:largeHeap="true">
</application>

它将为您的应用分配大堆。祝你好运:))

答案 2 :(得分:4)

如果出现OutOfMemory异常,则会出现最大图像尺寸问题。

  

您可以调整图片大小,例如

 Picasso.with(context)
                            .load(new File(arrayList.get(position).getUrl()))
                            .networkPolicy(NetworkPolicy.NO_CACHE)
                            .memoryPolicy(MemoryPolicy.NO_CACHE)
                            .resize(300,300)
                            .error(R.drawable.placeholder_full_image)
                            .placeholder(R.drawable.placeholder_full_image)
                            .into(genericViewHolder.productImage_iv);

这对我有用

答案 3 :(得分:2)

您的循环无限循环,因此您的应用内存不足。 请尝试以下步骤 onCreate-&GT; ChangeLanguage-&GT; RestartActivity-&GT; onCreate-&GT; ChangeLanguage-&GT; RestartActivity ...

你需要以某种方式结束它。

答案 4 :(得分:1)

OutOfMemoryError:无法分配458字节分配1613776空闲字节和1575KB直到OOM;由于碎片而失败(对于一个新的缓冲区需要连续的空闲32768字节,其中最大的连续空闲4096字节)

因此,应用程序试图从它拥有的1613776个空闲字节中分配458个字节,但由于碎片而失败,它无法为新缓冲区找到32768个空闲字节。

article解释说这是因为操作系统管理不好。 我已经在使用Android 5和6的手机上的应用程序中看到了这个问题,我不认为作为开发人员我们可以做些什么来修复它。