android – Can RecyclerView with onClickListener in constructor cause memory leak?-ThrowExceptions

Exception or error:

everyone!

I was searching through the internet but couldn’t find an answer to my question. Could such implementation cause a memory leak:

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    return SomeViewHolder(parent.inflate(R.layout.some_layout), listener)
}

Listener passed into the constructor is a simple interface implemented in the activity and passed through constructor into an adapter.

Thanks for help!

How to solve:

Could it? Maybe, depending on what the rest of your code is.

But as long as you’re not moving this between Activitys, including retaining it across configuration changes in a Fragment with setRetainInstance(true), this, alone, should not cause a memory leak.

Leave a Reply

Your email address will not be published. Required fields are marked *