fresco icon indicating copy to clipboard operation
fresco copied to clipboard

Gif cache doesn't seem to be working.

Open WhileCrow opened this issue 3 years ago • 1 comments

Description

Every time I load the same gif, all the frame caches for the gif are re-generated in memory. Is this a bug?Or GIF caching now not supported?

Reproduction

class TestWebpActivity : AppCompatActivity() {
    private var mRecyclerView: RecyclerView? = null
    private val mTvNoResult: TextView? = null
    private var mAdapter: WebpAdapter? = null
    private val mDatas = ArrayList<String>()
    private var mContext: Context? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_webplist)
        mRecyclerView = findViewById(R.id.recy)
        mContext = this
        testData()
        bindDatas()
    }

    private fun testData() {
        mDatas.add("https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/200px-Rotating_earth_%28large%29.gif")
    }

    fun bindDatas() {
        mAdapter = WebpAdapter()
        mRecyclerView!!.layoutManager = LinearLayoutManager(this)
        mRecyclerView!!.setHasFixedSize(true)
        mRecyclerView!!.adapter = mAdapter
    }

    private inner class WebpAdapter : RecyclerView.Adapter<VH>() {
        private val items: MutableList<String> = ArrayList()
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
            return VH(LayoutInflater.from(mContext).inflate(R.layout.item_test_webplist, parent, false))
        }

        override fun getItemCount(): Int {
            return items.size
        }

        override fun onBindViewHolder(holder: VH, position: Int) {
            val url = items[position]
            holder.tv.text = url

            val width = 100
            val height = 100
            val request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
                    .setResizeOptions(ResizeOptions(width, height))
                    .build()
            val controller = Fresco.newDraweeControllerBuilder()
                    .setOldController(holder.img.getController())
                    .setImageRequest(request)
                    .setAutoPlayAnimations(true)
                    .build();
            holder.img.controller = controller



            if (url.contains(".gif")) {
                Thread {
                    while (true) {
                        Thread.sleep(1000)
                        Handler(mainLooper).post {
                            val height = 100
                            val request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
                                    .setResizeOptions(ResizeOptions(width, height))
                                    .build()
                            val controller = Fresco.newDraweeControllerBuilder()
                                    .setOldController(holder.img.getController())
                                    .setImageRequest(request)
                                    .setAutoPlayAnimations(true)
                                    .build()
                            holder.img.controller = controller
                        }
                    }
                }.start()
            }
        }

        inner class VH(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val tv: TextView
            val img: SimpleDraweeView

            init {
                tv = itemView.findViewById<View>(R.id.tv_newurl) as TextView
                img = itemView.findViewById<View>(R.id.test_img) as SimpleDraweeView
            }
        }

        init {
            items.clear()
            items.addAll(mDatas)
        }
    }
}

Every second I reload this GIF (only 44 frames),android profiler show the memory keeps increasing until gc, and I find there are many frame cache in the cache pool (more than hundreds).

It appears that the cache keys are different every time the same GIF is loaded, so ImagePipelline repeatedly caches all frames of the same GIF.

image

image

Have I described it clearly and what additional information is needed?

Additional Information

  • Fresco version: [2.2.0]

WhileCrow avatar May 17 '21 08:05 WhileCrow

can i work on this issue @oprisnik ?

ashwanth511 avatar May 03 '23 17:05 ashwanth511