0

What is GC_BEFORE_OOM here? I think this is related with garbage collection in Java, but I do not know what is happening here.

09-08 15:42:18.568  29597-29597/jp.co.example D/dalvikvm﹕ GC_BEFORE_OOM freed 353K, 22% free 57872K/73443K, paused 35ms, total 36ms
09-08 15:42:18.568  29597-29597/jp.co.example E/dalvikvm-heap﹕ Out of memory on a 640016-byte allocation.
09-08 15:42:18.568  29597-29597/jp.co.example I/dalvikvm﹕ "main" prio=5 tid=1 RUNNABLE
09-08 15:42:18.569  29597-29597/jp.co.example I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x40aa3460 self=0xc598e0
09-08 15:42:18.569  29597-29597/jp.co.example I/dalvikvm﹕ | sysTid=29597 nice=0 sched=0/0 cgrp=default handle=1074087304
09-08 15:42:18.569  29597-29597/jp.co.example I/dalvikvm﹕ | schedstat=( 6092879000 2120586000 7353 ) utm=517 stm=92 core=0
09-08 15:42:18.569  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.Bitmap.nativeCreate(Native Method)
09-08 15:42:18.570  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
09-08 15:42:18.570  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
09-08 15:42:18.570  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
09-08 15:42:18.570  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:545)
09-08 15:42:18.570  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:520)
09-08 15:42:18.571  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:363)
09-08 15:42:18.571  29597-29597/jp.co.example I/dalvikvm﹕ at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)

What I have researched

In this fragment, setBackgroundResource() is called several times, therefore it can be said that it is obvious that loading images here would lead to the OutOfMemoryError. It seems that there are some other people who are confronted with the same problem.

Therefore, I have read below post by the official Android Developer:

And I have tried these, but the post says nothing about garbage collection or GC_BEFORE_OOM in Android.

These methods attempt to allocate memory for the constructed bitmap and therefore can easily result in an OutOfMemory exception.

So, my question is...

  • What is GC_BEFORE_OOM above?
  • And what is happening behind it?

Would anyone help?

Community
  • 1
  • 1
kenju
  • 5,866
  • 1
  • 41
  • 41

1 Answers1

2

Garbage Collection before OutOfMemoryError.

Before OOM is thrown, the VM will attempt to garbage collect and keep running. If the collection doesn't release enough memory, you get an OutOfMemoryError (which is what happens above).

Kayaman
  • 72,141
  • 5
  • 83
  • 121