kotterknife
kotterknife copied to clipboard
Added Butterknife.reset() for reseting cached views
Updated @MichaelRocks approach for the newest kotterknife version #5
according to WeakHashMap javadoc:
The value objects in a WeakHashMap are held by ordinary strong references. Thus care should be taken to ensure that value objects do not strongly refer to their own keys, either directly or indirectly, since that will prevent the keys from being discarded. Note that a value object may refer indirectly to its key via the WeakHashMap itself; that is, a value object may strongly refer to some other key object whose associated value object, in turn, strongly refers to the key of the first value object. One way to deal with this is to wrap values themselves within WeakReferences before inserting, as in: m.put(key, new WeakReference(value)), and then unwrapping upon each get.
And in your implementation: WeakHashMap
will hold a strong reference to MutableCollection
, MutableCollection
will hold a strong reference to Lazy
, Lazy
will hold a strong reference to some View
in an activity. According to Android source code, View
will hold a strong reference to Activity
, this will prevent Activity from being garbage collected.
@cmicat WeakHashMap
will hold a strong reference to MutableCollection
, which is another WeakHashMap
. So no, nothing will prevent an Activity
from being GCed. But the original patch is one and a half year old so who cares?
OK, it's my fault, but somewhat I can't find getOrPut
definition.
Maybe kotlin stdlib's change?
getOrPut
existed in Kotlin for ages and still presents in stdlib.
We need this functionality to correctly implement Fragments being detached and re-attached (ex: ViewPager).
I have forked the project, merged this PR, updated everything to latest and published it on JitPack if anybody is interested: https://github.com/rubengees/kotterknife