In my attempt to abstract out common functionality for all the adapters in my application I come across something while looking through ArrayAdapter code that is bothering me.
From what I know the common pattern of using ListView is like follow:
- Create ListView in XML which will have a reference in Activity.
- Create an ArrayAdapter and give Activity as context to it.
- Set the ArrayAdapter in ListView.
A glance at code shows that ListView stores a strong reference to adapter and ArrayAdapter stores a strong reference to context i.e. my Activity. This creates a strong reference cycle and that is what bothering me a bit.
I know that this could be overcome by setting ListView reference to null in onDestroy. But this issues is never discussed in any tutorial while using the same technique that causes it.
My question is am I missing something here or it is common knowledge?