Skip to content

Instantly share code, notes, and snippets.

@srcreigh
Created August 18, 2014 06:26
Show Gist options
  • Save srcreigh/9651f643ad0cb7d11c12 to your computer and use it in GitHub Desktop.
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