Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gif cache doesn't seem to be working. #2605

Open
WhileCrow opened this issue May 17, 2021 · 1 comment
Open

Gif cache doesn't seem to be working. #2605

WhileCrow opened this issue May 17, 2021 · 1 comment
Assignees
Labels

Comments

@WhileCrow
Copy link

WhileCrow commented May 17, 2021

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]
@ashwanth511
Copy link

can i work on this issue @oprisnik ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants