15

This app worked yesterday, but when starting to work this morning, I get the following error

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

I have no idea what's going on, or why it's out of memory. Is this just the emulator not working perfectly? Or does this have something to do with my app?

I don't know how much information you need. If you need further information, please tell me so and I will provide.

UPDATE:

I guess this has something to do with the garbage collector? Refer below

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

Actual red text:

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)

EDIT: JAVA CODE

@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);
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
Detilium
  • 2,868
  • 9
  • 30
  • 65
  • 1
    are you using bitmaps in your app? – Oli Jul 22 '15 at 06:25
  • 1
    @Oli Pictures? yes `android:background="@drawable/backgroundimage"` – Detilium Jul 22 '15 at 06:28
  • 1
    Try adding `android:largeHeap="true"` in your application tag on `AndroidManifest.xml` – Oli Jul 22 '15 at 06:37
  • @Oli requires API level 11, mine is 10 as I want to hit a bigger market – Detilium Jul 22 '15 at 06:39
  • What is the size in KB and resolution of `backgroundimage`. Also, which `/drawable` folder do you have this file in? – Awanish Raj Jul 22 '15 at 06:45
  • @AwanishRaj It's 281 kb and placed in the `\drawable-hdpi` Res: 750x500 – Detilium Jul 22 '15 at 06:46
  • Ok. Assigning a resource directly from xml sometimes causes memory issues, because the system tries to load the entire bitmap. But, in your case the file isn't that big. Can you try removing this temporarily and see if problem persists? – Awanish Raj Jul 22 '15 at 06:48
  • @AwanishRaj I tried commenting it out in the `activity_main.xml` which is the startup layout, but no difference – Detilium Jul 22 '15 at 06:51
  • 1
    I just saw your stack trace. Also, post relevant java code here! Problem seems to be not in the image but in constructing a string somewhere! – Awanish Raj Jul 22 '15 at 06:51
  • @AwanishRaj Hang on a sec. I had language control before (The user could change between language using tiny "flags" in the app main menu), but my coworker wanted me to just throw this app out as danish to start with, so I'm trying to make the language danish to start with. See edit in main question – Detilium Jul 22 '15 at 06:56
  • @AwanishRaj Removing the language change made the app work again without problems – Detilium Jul 22 '15 at 07:02
  • Possible duplicate of [How to solve java.lang.OutOfMemoryError trouble in Android](https://stackoverflow.com/questions/25719620/how-to-solve-java-lang-outofmemoryerror-trouble-in-android) – Zoe Jun 14 '19 at 15:19

5 Answers5

7

Try this may help you add this tag in your manifest file.

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

it will allocate large heap for your app. Best of luck :)

  • Thanks for the suggestion. Although that one will help in general against out of memory crashes, I still get the error here. And I do have one really big images as some other comments mention. – jeevium Jan 11 '19 at 09:21
6

This kind of error usually occur when you use REALLY BIG images in your project. Try to downscale your images and this error is solved.

If you don't use some sort of professional image editing software like Photoshop or Illustrator, you can do this simple task with your built-in image viewer.

On a Mac, you can use the Preview app to downscale your images.

  • Open your image with Preview (simply double click your image, Preview is the default app).
  • Select the Markup Toolbar (looks like a briefcase).
  • Click on the Adjust Size button (looks like a square with two arrows at it's opposite corners).
  • Enter your desired Width and Height.
  • Click OK, and you are done =)

** I don't use a PC, so I can't explain how to go about it on such, but it should be very simple as well.

I hope it helps someone...

Barakuda
  • 790
  • 8
  • 16
6

In case of OutOfMemory exception maximum times image size issue occur.

You can resize you image for example

 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);

it is work for me

Akshay Barodia
  • 486
  • 4
  • 11
4

You've got an infinite loop going so your app is running out of memory. Try the following steps onCreate->ChangeLanguage->RestartActivity->onCreate->ChangeLanguage->RestartActivity...

You need to end it somehow.

MohanRaj S
  • 1,958
  • 4
  • 30
  • 54
joobarr
  • 41
  • 1
4

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)

So the app tried to allocate 458 bytes out of the 1613776 free bytes that it had, but failed due to fragmentation, it could not find 32768 free continguous bytes for a new buffer.

This article explains that it is because the OS has poor ram management. I've seen this issue happening in my app on phones with Android 5 and 6, and I don't think that as developers we can do something to fix it.

xarlymg89
  • 2,552
  • 2
  • 27
  • 41
Goran Horia Mihail
  • 3,536
  • 2
  • 29
  • 40
  • Article link not valid anymore. However, I upvote your comment since it happened precisely in an Android 5 device. It'd be useful if you could share another link that works with an explanation about this matter though. – xarlymg89 Jun 14 '19 at 07:32
  • 2
    https://web.archive.org/web/20180429154436/http://rebrn.com/re/poor-ram-management-affecting-the-galaxy-s-and-s-edge-189814/ good thing we have web archive – Goran Horia Mihail Jun 14 '19 at 07:34