Selecting a big cover image fails due to OutOfMemoryError, and activity might be leaking memory

Bug #767567 reported by pjv
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Collectionista
Fix Released
Medium
Unassigned

Bug Description

Several errors apply:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:574)
at net.lp.collectionista.domain.items.cd.CDItem$CDArtworkCreator.addReflection(CDItem.java:136)
at net.lp.collectionista.domain.items.cd.CDItem$CDArtworkCreator.createCover(CDItem.java:195)
at net.lp.collectionista.util.CoverManager.returnAndCacheCover(CoverManager.java:126)
at net.lp.collectionista.util.CoverManager.returnCover(CoverManager.java:152)
at net.lp.collectionista.domain.items.cd.CDItem.changeCover(CDItem.java:408)
at net.lp.collectionista.ui.activities.items.cd.music.MusicCDItemEditWindow$4.changeCover(MusicCDItemEditWindow.java:217)
at net.lp.collectionista.ui.activities.items.cd.music.MusicCDItemEditWindow.onActivityResultAfterResume(MusicCDItemEditWindow.java:334)
at net.lp.collectionista.ui.activities.RegularEditWindow.onResume(RegularEditWindow.java:635)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1255)
at android.app.Activity.performResume(Activity.java:3864)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3337)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3362)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2162)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:468)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:528)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:529)
at net.lp.collectionista.util.ImageUtilities.loadImageResource(ImageUtilities.java:417)
at net.lp.collectionista.util.ImageUtilities.getImage(ImageUtilities.java:434)
at net.lp.collectionista.domain.items.book.BookItem.getCoverImageForFormField(BookItem.java:1221)
at net.lp.collectionista.ui.activities.items.book.BookItemEditWindow$6.perform(BookItemEditWindow.java:526)
at net.lp.collectionista.ui.activities.collections.ImageRepresentationLoader$1.run(ImageRepresentationLoader.java:47)
at java.lang.Thread.run(Thread.java:1102)

Related branches

pjv (pjv)
Changed in collectionista:
importance: Undecided → Low
importance: Low → Medium
Revision history for this message
pjv (pjv) wrote :

via dev con (3+2 reports):

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at net.lp.collectionista.domain.items.cd.CDItem$CDArtworkCreator.addReflection(CDItem.java:136)
at net.lp.collectionista.domain.items.cd.CDItem$CDArtworkCreator.createCover(CDItem.java:195)
at net.lp.collectionista.util.CoverManager.returnAndCacheCover(CoverManager.java:126)
at net.lp.collectionista.util.CoverManager.returnCover(CoverManager.java:152)
at net.lp.collectionista.domain.items.cd.CDItem.changeCover(CDItem.java:408)
at net.lp.collectionista.ui.activities.items.cd.music.MusicCDItemEditWindow$4.changeCover(MusicCDItemEditWindow.java:219)
at net.lp.collectionista.ui.activities.items.cd.music.MusicCDItemEditWindow.onActivityResultAfterResume(MusicCDItemEditWindow.java:336)
at net.lp.collectionista.ui.activities.RegularEditWindow.onActivityResult(RegularEditWindow.java:213)
at android.app.Activity.dispatchActivityResult(Activity.java:3907)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2500)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2546)
at android.app.ActivityThread.access$2000(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:966)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3652)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:529)
at net.lp.collectionista.util.ImageUtilities.loadImageResource(ImageUtilities.java:417)
at net.lp.collectionista.util.ImageUtilities.getImage(ImageUtilities.java:434)
at net.lp.collectionista.domain.items.book.BookItem.getCoverImageForFormField(BookItem.java:1221)
at net.lp.collectionista.ui.activities.items.book.BookItemEditWindow$6.perform(BookItemEditWindow.java:528)
at net.lp.collectionista.ui.activities.collections.ImageRepresentationLoader$1.run(ImageRepresentationLoader.java:47)
at java.lang.Thread.run(Thread.java:1019)

Revision history for this message
pjv (pjv) wrote :

Solved the first one by recycling bitmaps.

Solved the second by in one place using an advanced bitmap opening technique which lets the BitmapFactory prescale the image (but needs to look at the bitmap twice, one time beforehand to give me the bounds so I can calculate the sample ratio). Both MediaStore.Images.Media.getBitmap() and MediaStore.Images.Thumbnails.getThumbnail() were insufficient, though this method is still technically equivalent to getBitmap(), with the added sampling.

Revision history for this message
pjv (pjv) wrote :

bitmap.recycle() that is.

pjv (pjv)
Changed in collectionista:
status: New → Fix Committed
pjv (pjv)
Changed in collectionista:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.