Skip to content

Instantly share code, notes, and snippets.

@alexvbush
Last active July 6, 2016 18:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexvbush/7177814 to your computer and use it in GitHub Desktop.
Save alexvbush/7177814 to your computer and use it in GitHub Desktop.
An example of how to store an Android Context object in a weak reference to avoid unexpected retain loops in adapters and such.
public class ExampleWeak {
private WeakReference<Context> weakContext;
public ExammpleWeak(Context context) {
this.weakContext = context;
}
public Context getContext() {
return weakContext.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment