Skip to content

Instantly share code, notes, and snippets.

@srcreigh
Created August 18, 2014 06:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save srcreigh/9651f643ad0cb7d11c12 to your computer and use it in GitHub Desktop.
Set<WeakReference<TextView>> toRemove = new HashSet<WeakReference<TextView>>();
for (WeakReference<TextView> weakRef : textviews) {
TextView textView = weakRef.get();
if (textView != null) {
// do stuff here
} else {
toRemove.add(weakRef);
}
}
// remove all the unnecessary WeakReferences from your set
textviews.removeAll(toRemove);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment