Reputation: 5105
I've been experimenting Shared elements transitions with Android-L preview (Nexus 7), and faced OutOfMemoryError
exceptions when used with a ViewPager
. But I also tried on Romain's google-io-2014 demo, and got the same problem after clicking on a picture then hitting back, a couple of times (between 10 to 15). Is it a bug in the SDK, and there's something that should be done on the application side (recycle()
)?
java.lang.OutOfMemoryError: Failed to allocate a 1817612 byte allocation with 772936 free bytes
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:810)
at android.graphics.Bitmap.createBitmap(Bitmap.java:787)
at android.graphics.Bitmap.createBitmap(Bitmap.java:754)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:543)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:511)
at android.app.EnterTransitionCoordinator.sendSharedElementDestination(EnterTransitionCoordinator.java:109)
at android.app.EnterTransitionCoordinator.onReceiveResult(EnterTransitionCoordinator.java:151)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:738)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
I/am_crash( 612): [17912,0,com.example.android.io2014,8961606,java.lang.OutOfMemoryError,Failed to allocate a 1817612 byte allocation with 772936 free bytes,VMRuntime.java,-2]
Update (10/17/2014): all fixed with SDK 21. Can't close the question.
Upvotes: 1
Views: 491
Reputation: 83303
Apparently this has been fixed in API 21 (according to the OP).
Note also that Romain Guy's sample project is just an example... he didn't bother writing code that properly scales down the images he uses (which is what you would normally do in a production application). If you are running the sample on a low-end device, it's possible that you might get out of memory errors. To avoid this, I recommend resizing and scaling down the drawable PNGs included in the project.
Upvotes: 1