Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Added Butterknife.reset() for reseting cached views #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pouljohn1
Copy link

Updated @MichaelRocks approach for the newest kotterknife version #5

@cmicat
Copy link

cmicat commented May 10, 2016

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.

@MichaelRocks
Copy link

MichaelRocks commented May 10, 2016

@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?

@cmicat
Copy link

cmicat commented May 10, 2016

OK, it's my fault, but somewhat I can't find getOrPut definition.
Maybe kotlin stdlib's change?

@MichaelRocks
Copy link

getOrPut existed in Kotlin for ages and still presents in stdlib.

@tinsukE
Copy link
Contributor

tinsukE commented Aug 8, 2017

We need this functionality to correctly implement Fragments being detached and re-attached (ex: ViewPager).

@rubengees
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants