question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OutOfMemoryError when loading images into ViewPager

See original GitHub issue

I use Picasso to load images from app resources into ViewPager. Today I’ve faced the crash when I scroll ViewPager pages very fast. I recieved folowing error log:

08-13 13:10:33.968: ERROR/dalvikvm-heap(7896): Out of memory on a 1405456-byte allocation.
08-13 13:10:34.818: ERROR/dalvikvm(7896): can't open /data/misc/hprof_oom_dump.hprof: Permission denied
08-13 13:10:34.928: ERROR/Bitmap(7896): [FXN.ASD] Unable to create bitmap file. OutOfMemoryError.
        java.lang.OutOfMemoryError
        at android.graphics.Bitmap.nativeCreate(Native Method)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:645)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:587)
        at com.squareup.picasso.Picasso.transformResult(Picasso.java:479)
        at com.squareup.picasso.Picasso.loadFromType(Picasso.java:401)
        at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:240)
        at com.squareup.picasso.Picasso.run(Picasso.java:218)
        at com.squareup.picasso.Request.run(Request.java:100)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
        at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:267)
08-13 13:10:34.998: ERROR/AndroidRuntime(7896): FATAL EXCEPTION: main
        java.lang.RuntimeException: An unexpected exception occurred
        at com.squareup.picasso.Request$1.run(Request.java:106)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4802)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at android.graphics.Bitmap.createBitmap(Bitmap.java:602)
        at com.squareup.picasso.Picasso.transformResult(Picasso.java:479)
        at com.squareup.picasso.Picasso.loadFromType(Picasso.java:401)
        at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:240)
        at com.squareup.picasso.Picasso.run(Picasso.java:218)
        at com.squareup.picasso.Request.run(Request.java:100)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
        at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:267)
08-13 13:10:35.228: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.
08-13 13:10:35.718: ERROR/wpa_supplicant(3206): ctrl_iface cmd = SIGNAL_POLL
08-13 13:10:36.188: ERROR/dalvikvm(7896): can't open /data/misc/hprof_oom_dump.hprof: Permission denied
08-13 13:10:36.298: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.
08-13 13:10:37.348: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.
08-13 13:10:38.278: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.

Here is code from my PagerAdapter where I load images:

@Override
    public View instantiateItem(ViewGroup container, int position) {
        View pagerItem = layoutInflater.inflate(R.layout.pager_item_wallpaper, container, false);
        ImageView imgWallpaper = (ImageView) pagerItem.findViewById(R.id.wallpaper);
        Picasso.with(context).load(wallpapers.get(position)).fit().into(imgWallpaper);
        container.addView(pagerItem);
        return pagerItem;
    }

I use Picasso version 1.1.1. Is something wrong with my code?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
JakeWhartoncommented, Aug 13, 2013

This isn’t really a Picasso problem. You’re telling it to load images and it is. The problem is that you’re loading a ton of relatively large images and blowing your heap. We can’t do anything about it. You need to optimize how the images are presented to ensure things like this don’t happen. You might want to consider calling skipCache() so the images aren’t kept in memory longer than they need to.

0reactions
Pukhrajwdgcommented, Aug 1, 2021

I use Picasso to load images from app resources into ViewPager. Today I’ve faced the crash when I scroll ViewPager pages very fast. I recieved folowing error log:

08-13 13:10:33.968: ERROR/dalvikvm-heap(7896): Out of memory on a 1405456-byte allocation.
08-13 13:10:34.818: ERROR/dalvikvm(7896): can't open /data/misc/hprof_oom_dump.hprof: Permission denied
08-13 13:10:34.928: ERROR/Bitmap(7896): [FXN.ASD] Unable to create bitmap file. OutOfMemoryError.
        java.lang.OutOfMemoryError
        at android.graphics.Bitmap.nativeCreate(Native Method)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:645)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:587)
        at com.squareup.picasso.Picasso.transformResult(Picasso.java:479)
        at com.squareup.picasso.Picasso.loadFromType(Picasso.java:401)
        at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:240)
        at com.squareup.picasso.Picasso.run(Picasso.java:218)
        at com.squareup.picasso.Request.run(Request.java:100)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
        at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:267)
08-13 13:10:34.998: ERROR/AndroidRuntime(7896): FATAL EXCEPTION: main
        java.lang.RuntimeException: An unexpected exception occurred
        at com.squareup.picasso.Request$1.run(Request.java:106)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4802)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:813)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:580)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.NullPointerException
        at android.graphics.Bitmap.createBitmap(Bitmap.java:602)
        at com.squareup.picasso.Picasso.transformResult(Picasso.java:479)
        at com.squareup.picasso.Picasso.loadFromType(Picasso.java:401)
        at com.squareup.picasso.Picasso.resolveRequest(Picasso.java:240)
        at com.squareup.picasso.Picasso.run(Picasso.java:218)
        at com.squareup.picasso.Request.run(Request.java:100)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
        at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:267)
08-13 13:10:35.228: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.
08-13 13:10:35.718: ERROR/wpa_supplicant(3206): ctrl_iface cmd = SIGNAL_POLL
08-13 13:10:36.188: ERROR/dalvikvm(7896): can't open /data/misc/hprof_oom_dump.hprof: Permission denied
08-13 13:10:36.298: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.
08-13 13:10:37.348: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.
08-13 13:10:38.278: ERROR/dalvikvm-heap(7896): Out of memory on a 3686416-byte allocation.

Here is code from my PagerAdapter where I load images:

@Override
    public View instantiateItem(ViewGroup container, int position) {
        View pagerItem = layoutInflater.inflate(R.layout.pager_item_wallpaper, container, false);
        ImageView imgWallpaper = (ImageView) pagerItem.findViewById(R.id.wallpaper);
        Picasso.with(context).load(wallpapers.get(position)).fit().into(imgWallpaper);
        container.addView(pagerItem);
        return pagerItem;
    }

I use Picasso version 1.1.1. Is something wrong with my code?

java.lang.RuntimeException: excessive total memory usage, total usage 1605 MB at com.vivo.vspa.AppThreadCmd$2.run(AppThreadCmd.java:84) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:239) at android.app.ActivityThread.main(ActivityThread.java:8149) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1015) help me out

Read more comments on GitHub >

github_iconTop Results From Across the Web

Out of Memory Error when loading images to a View Pager ...
I have a Viewpager using the cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2 library. I keep getting an OOM ...
Read more >
Android – Loading large bitmaps to ImageView in ViewPager – out ...
I have ViewPager which I use to show zoomable images (using ImageViewTouch). I need to load large bitmaps from Internet (http). By large...
Read more >
Caching Bitmaps - Android Developers
Loading a single bitmap into your user interface (UI) is straightforward, however things get more complicated if you need to load a larger...
Read more >
Multiple Recycler GridViews in a Fragment ViewPager ...
If I create a single Recyclerview without any ViewPager adapters, and load 1650 image resources in the list, it scrolls through, ...
Read more >
Xamarin Android OutOfMemoryError large images in view ...
[Solved]-Xamarin Android OutOfMemoryError large images in view pager-xamarin ... 1) You are in C#: Use .Dispose on your image instead of .Recycle, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found