2

I’m using Picasso in my app for download and cache images.
its Work great but there is a problem : app has a lot of images and after a short time app cache increase over 10 MB !

after long search I found this solution for limiting cache in Picasso but doesn’t work :

 private void initPicaso() {
        // Create memory cache
        Cache memoryCache = new LruCache((int) PICASSO_DISK_CACHE_SIZE);

        Picasso mPicasso = new Picasso.Builder(getApplicationContext())
                .memoryCache(memoryCache).build();
        Picasso.setSingletonInstance(mPicasso);
    }   

Im using this method in onCreate of my app application class .
What is wrong in my work ? or is there other way to achieve this ?
{i hope explain my problem clear :/ }

YFeizi
  • 1,498
  • 3
  • 28
  • 50

3 Answers3

0

Hi recently i faced this issue while loading so many image in application.Try with Universal Image Loader library
https://github.com/nostra13/Android-Universal-Image-Loader

clear cache : https://github.com/nostra13/Android-Universal-Image-Loader/issues/138

  • Im using Picasso in depth of my app ! its easier to ignore this problem than changing library . any way thanks for your reply – YFeizi Sep 23 '15 at 06:36
0

I think you should not use LruCache in this case because Picasso already caching your images. The problem which I identify in your case is that may be some of your images are very large. For this case you will use resize method of Picasso. And apply this only for large size image. And to achieve this you should use Target(), look at the following code:

          if (loadtarget == null){
                loadtarget = new Target() {

                @Override
                public void onBitmapLoaded(Bitmap bitmap,
                        Picasso.LoadedFrom from) {
                    imageView.setImageBitmap(bitmap);
                }

                @Override
                public void onPrepareLoad(Drawable arg0) {
                    imageView.setImageResource(R.drawable.place_holder);
                }

                @Override
                public void onBitmapFailed(Drawable arg0) {
                    Picasso.with(MaxSupportApp.context).load(url)
                    .resize(300, 300).error(R.drawable.place_holder)
                    .into(imageView);
                }
            };
            Picasso.with(MaxSupportApp.context).load(url)
            .into(loadtarget);
  • My Images are not large , most of them are less than 200Kb (180px * 110px ) but i have alot of images (Its a shop application) . also i can use resize without target i think :) – YFeizi Sep 23 '15 at 06:35
  • Yes, you can resize without Target but for resizing only large images you should use Targets. See in my code i applied resize when bitmap failed to load. – Abdullah Mehmood Sep 23 '15 at 07:02
  • Can you explain what actual scenario happens in your case. Like, is your app crashes or images are not displaying??? – Abdullah Mehmood Sep 23 '15 at 07:04
0

Maybe the integer PICASSO_DISK_CACHE_SIZE you defined has the same value with the value that Picasso uses itself depend on your device.Try reduce the value. But reduce memory cache size maybe causes the flash on each imageView. I recommend you to use Glide instead of Picasso. Picasso uses ARGB_8888 but glide uses RGB_565 and you can see the memory footprint in the document below.

Take a look at this Document.

Armin Ghoreishi
  • 56
  • 2
  • 12