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

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

Open
pouljohn1 wants to merge 1 commit into
JakeWharton:masterfrom
pouljohn1:master
Open

Added Butterknife.reset() for reseting cached views #37
pouljohn1 wants to merge 1 commit into
JakeWharton:masterfrom
pouljohn1:master

Conversation

@pouljohn1

Copy link
Copy Markdown

Updated @MichaelRocks approach for the newest kotterknife version #5

@cmicat

cmicat commented May 10, 2016

Copy link
Copy Markdown

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

MichaelRocks commented May 10, 2016

Copy link
Copy Markdown

@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

cmicat commented May 10, 2016

Copy link
Copy Markdown

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

@MichaelRocks

Copy link
Copy Markdown

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

@tinsukE

tinsukE commented Aug 8, 2017

Copy link
Copy Markdown
Contributor

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

@rubengees

Copy link
Copy Markdown

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