facebookarchive / shimmer-android

An easy, flexible way to add a shimmering effect to any view in an Android app.
http://facebook.github.io/shimmer-android/
Other
5.32k stars 697 forks source link

Out of memory error #40

Closed knightcube closed 6 years ago

knightcube commented 6 years ago

I have a bottom navigation bar. There are 4 options A,B,C and D. When i try to swiftly click A and B, after a couple of clicks the app crashes and the log is below. How do i fix it?

 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.rajatcube.sharstory, PID: 11461
                                                                         java.lang.OutOfMemoryError: Failed to allocate a 6234636 byte allocation with 5477368 free bytes and 5MB until OOM
                                                                             at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                             at android.graphics.Bitmap.nativeCreate(Native Method)
                                                                             at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
                                                                             at android.graphics.Bitmap.createBitmap(Bitmap.java:948)
                                                                             at android.graphics.Bitmap.createBitmap(Bitmap.java:915)
                                                                             at com.facebook.shimmer.ShimmerFrameLayout.createBitmapAndGcIfNecessary(ShimmerFrameLayout.java:946)
                                                                             at com.facebook.shimmer.ShimmerFrameLayout.getMaskBitmap(ShimmerFrameLayout.java:822)
                                                                             at com.facebook.shimmer.ShimmerFrameLayout.drawMasked(ShimmerFrameLayout.java:771)
                                                                             at com.facebook.shimmer.ShimmerFrameLayout.dispatchDrawUsingBitmap(ShimmerFrameLayout.java:720)
                                                                             at com.facebook.shimmer.ShimmerFrameLayout.dispatchDraw(ShimmerFrameLayout.java:697)
                                                                             at android.view.View.draw(View.java:18401)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17376)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             at android.view.View.draw(View.java:18160)
                                                                             at android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             at android.view.View.draw(View.java:18401)
                                                                             at com.android.internal.policy.DecorView.draw(DecorView.java:966)
                                                                             at android.view.View.updateDisplayListIfDirty(View.java:17376)
                                                                             at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:722)
                                                                             at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:728)
                                                                             at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:836)
                                                                             at android.view.ViewRootImpl.draw(ViewRootImpl.java:3168)
                                                                             at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2964)
                                                                             at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2552)
                                                                             at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
                                                                             at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
                                                                             at android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
                                                                             at android.view.Choreographer.doCallbacks(Choreographer.java:734)
                                                                             at android.view.Choreographer.doFrame(Choreographer.java:670)
                                                                             at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
                                                                             at android.os.Handler.handleCallback(Handler.java:751)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                             at android.os.Looper.loop(Looper.java:154)

I think this part will also be useful -

D/ShimmerFrameLayout: ShimmerFrameLayout failed to create working bitmap (width = 1056, height = 1476)

                                                                             dalvik.system.VMStack.getThreadStackTrace(Native Method)
                                                                             java.lang.Thread.getStackTrace(Thread.java:1567)
                                                                             com.facebook.shimmer.ShimmerFrameLayout.tryCreateRenderBitmap(ShimmerFrameLayout.java:754)
                                                                             com.facebook.shimmer.ShimmerFrameLayout.tryObtainRenderMaskBitmap(ShimmerFrameLayout.java:735)
                                                                             com.facebook.shimmer.ShimmerFrameLayout.dispatchDrawUsingBitmap(ShimmerFrameLayout.java:711)
                                                                             com.facebook.shimmer.ShimmerFrameLayout.dispatchDraw(ShimmerFrameLayout.java:697)
                                                                             android.view.View.draw(View.java:18401)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17376)
                                                                             android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3952)
                                                                             android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3932)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17339)
                                                                             android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3952)
                                                                             android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3932)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17339)
                                                                             android.view.View.draw(View.java:18160)
                                                                             android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             android.view.View.draw(View.java:18160)
                                                                             android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             android.view.View.draw(View.java:18160)
                                                                             android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             android.view.View.draw(View.java:18160)
                                                                             android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             android.view.View.draw(View.java:18160)
                                                                             android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17371)
                                                                             android.view.View.draw(View.java:18160)
                                                                             android.view.ViewGroup.drawChild(ViewGroup.java:3968)
                                                                             android.view.ViewGroup.dispatchDraw(ViewGroup.java:3754)
                                                                             android.view.View.draw(View.java:18401)
                                                                             com.android.internal.policy.DecorView.draw(DecorView.java:966)
                                                                             android.view.View.updateDisplayListIfDirty(View.java:17376)
                                                                             android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:722)
                                                                             android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:728)
                                                                             android.view.ThreadedRenderer.draw(ThreadedRenderer.java:836)
                                                                             android.view.ViewRootImpl.draw(ViewRootImpl.java:3168)
                                                                             android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2964)
                                                                             android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2552)
                                                                             android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1537)
                                                                             android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
                                                                             android.view.Choreographer$CallbackRecord.run(Choreographer.java:959)
                                                                             android.view.Choreographer.doCallbacks(Choreographer.java:734)
                                                                             android.view.Choreographer.doFrame(Choreographer.java:670)
                                                                             android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
                                                                             android.os.Handler.handleCallback(Handler.java:751)
                                                                             android.os.Handler.dispatchMessage(Handler.java:95)
                                                                             android.os.Looper.loop(Looper.java:154)
                                                                             android.app.ActivityThread.main(ActivityThread.java:6776)
                                                                             java.lang.reflect.Method.invoke(Native Method)
                                                                             com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
                                                                             com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
xiphirx commented 6 years ago

The new version of the library (that is currently unreleased) is much more memory efficient. I'll have to look into when I can release it...

ninad458 commented 5 years ago

I'm getting a similar ANR

2019-02-11 15:39:37.514 18440-18440/app.application E/AndroidRuntime: FATAL EXCEPTION: main Process: app.application, PID: 18440 java.lang.OutOfMemoryError: Failed to allocate a 5909772 byte allocation with 2583880 free bytes and 2MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:905) at android.graphics.Bitmap.createBitmap(Bitmap.java:882) at android.graphics.Bitmap.createBitmap(Bitmap.java:849) at com.facebook.shimmer.ShimmerFrameLayout.createBitmapAndGcIfNecessary(ShimmerFrameLayout.java:946) at com.facebook.shimmer.ShimmerFrameLayout.getMaskBitmap(ShimmerFrameLayout.java:822) at com.facebook.shimmer.ShimmerFrameLayout.drawMasked(ShimmerFrameLayout.java:771) at com.facebook.shimmer.ShimmerFrameLayout.dispatchDrawUsingBitmap(ShimmerFrameLayout.java:720) at com.facebook.shimmer.ShimmerFrameLayout.dispatchDraw(ShimmerFrameLayout.java:697) at android.view.View.draw(View.java:17089) at android.view.View.draw(View.java:16994) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:16992) at android.view.ViewGroup.drawChild(ViewGroup.java:3768) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3554) at android.view.View.draw(View.java:17089) at com.android.internal.policy.DecorView.draw(DecorView.java:751) at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2921) at android.view.ViewRootImpl.draw(ViewRootImpl.java:2835) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2616) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2223) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1258) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6348) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871) at android.view.Choreographer.doCallbacks(Choreographer.java:683) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6123) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)