christophesmet / android_maskable_layout

A library that easily allows you to mask layouts/viewgroups
Apache License 2.0
652 stars 145 forks source link

Out of memory on a 9193040-byte allocation. #40

Closed PrinceDholakiya closed 5 years ago

PrinceDholakiya commented 5 years ago
E/dalvikvm-heap: **Out of memory on a 9193040-byte allocation.**
I/dalvikvm: "main" prio=5 tid=1 RUNNABLE
I/dalvikvm:   | group="main" sCount=0 dsCount=0 obj=0x41763ca8 self=0x41641488
I/dalvikvm:   | sysTid=5961 nice=0 sched=0/0 cgrp=apps handle=1073865044
I/dalvikvm:   | state=R schedstat=( 0 0 0 ) utm=23035 stm=2509 core=1
I/dalvikvm:     at android.graphics.Bitmap.nativeCreate(Native Method)
I/dalvikvm:     at android.graphics.Bitmap.createBitmap(Bitmap.java:822)
I/dalvikvm:     at android.graphics.Bitmap.createBitmap(Bitmap.java:799)
I/dalvikvm:     at android.graphics.Bitmap.createBitmap(Bitmap.java:766)
I/dalvikvm:     **at  MaskableFrameLayout.makeBitmapMask(MaskableFrameLayout.java:140)**
I/dalvikvm:     **at MaskableFrameLayout.setMask(MaskableFrameLayout.java:172)**
I/dalvikvm:     at MainActivity$1.onResourceReady(MainActivity.java:211)
I/dalvikvm:     at ObCShapeMainActivity$1.onResourceReady(MainActivity.java:201)
I/dalvikvm:     at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:558)
I/dalvikvm:     at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:530)
I/dalvikvm:     at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:218)
I/dalvikvm:     at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:324)

I have got this error when I set a huge amount of Mask into setMask method one by one. Then sometimes it gives me OutOfMemory Error.

So my I hope you solve this error.

Suggestion for solving this error. Make bitmap variable global and when you have used it then recycle your bitmap.

christophesmet commented 5 years ago

Bitmaps are already recycled when they aren't being used anymore. I think you are either restricted in memory and your mask is too large. One way is to fix this is to expand the mask loading with bitmapfactory parameters