I heard that inner class use more memory than nested class in Kotlin.
And somebody said it is bad for using inner Class in RecyclerView(ViewHolder).
But, It was hard to use onClickListener without inner class.
I can't exactly understand why memory leak happens with inner class in RecyclerView.
And It is must to use nested class rather than inner class? then... what reason inner class exist for? Can somebody tell me answer?
I asked Chatgpt but it only say about memory leak.... I want to understand detail action about it!
At first you need to know the difference between Inner and Nested Classes
Also, you need to understand when and why Memory Leaks occur's in RecyclerView.
Again, you don't have to use nested classes always, but they can be handy when you want a closely connected class without access to its non-static parts or to prevent memory issues. Inner classes exist because they help keep related functions organized within a class, can access non-static parts easily, and offer more flexibility in certain situations. So, it's not a must, but they bring some cool benefits!
So, based on your situation, I can suggest you to use Lambda (my personal opinion). See example code snippet bellow -
Lamda is similar to anonymous classes, lambdas offer a concise way to define listeners without separate classes. This can improve code readability and avoid memory leaks.
Hope it helps!