Bad performance in Fresco with Recycler View, Possibly due to Kotlin?
See original GitHub issueReproduction
My app currently has a main page with ~60 images with a small text that are displayed using a recycler view and I would expect Fresco to handle fine since it should only be loading a few at a time, however I frequently get a “Pool Size Violation”. I’m not entirely sure if this is a fault on my side or on Fresco’s so I’m deciding to include snippets of my code
Note: It’s mostly in Kotlin, however I’m reluctant to say this is the problem since most of the interactions with Fresco are done through Java, however, I haven’t found any other faults
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.list, parent, false)
return ViewHolder(v)
}
//this method is binding the data on the list
override fun onBindViewHolder(holder: RecyclerViewAdapter.ViewHolder, position: Int) {
holder.bindItems(list[position])
}
//this method is giving the size of the list
override fun getItemCount(): Int {
return list.size
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindItems(data: MyData) {
val _imageView: SimpleDraweeView = itemView.findViewById(R.id.imageview)
_imageView.setOnClickListener {
Log.e("Click: ", data.imageURL)
}
//Call a Java method to set Image in Drawee
Required_Functions.setPicture(_imageView, data.imageURL)
//set the onclick listener for the singlt list item
itemView.setOnClickListener({
Log.e("ItemClicked", data.text)
})
}
}
}
And here’s my referenced “setPicture” function
public static void setPicture(SimpleDraweeView img, String img_location){
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(img_location))
.setResizeOptions(new ResizeOptions(100, 100))
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setOldController(img.getController())
.setImageRequest(request)
.build();
img.setController(controller);
}
Extra Information: I’m on fresco 1.5.0 and I’ve tried this out on my Nexus 6 and an S4. On the Nexus 6, the images load but upon scrolling I get the error above and the S4 crashes upon boot-up even though the pictures are resized to 100x100.
Thanks for helping!
Solution
I’m not really sure about this but my guess is since my recycler view is entirely done in kotlin, there is an incompatibility when detecting if a item is off the screen leading to the image never being taken out of memory.
Additional Information
- Fresco version: fresco 1.5.0
- Platform version: Not specific to any android version or device to my knowledge
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
The code is slightly problematic,in your bindItems method,should not be executed findViewBydId and setOnClickListener,should be in Kotlin’s secondary constructors
Hi @parthmahendra , can you share a bit more on what you find that’s missing in kotlin & recyclerview? Specifically: