Skip to content

Instantly share code, notes, and snippets.

@menny
Last active December 12, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menny/4747886 to your computer and use it in GitHub Desktop.
Save menny/4747886 to your computer and use it in GitHub Desktop.
Android Memory Leaks OR Different Ways to Leak
public class AnySoftKeyboard extends InputMethodService {
private static final class KeyboardUIStateHanlder extends Handler {
//This will NOT be counted as a reference!
private final WeakReference<AnySoftKeyboard> mKeyboard;
public KeyboardUIStateHanlder(AnySoftKeyboard keyboard) {
mKeyboard = new WeakReference<AnySoftKeyboard>(keyboard);
}
@Override
public void handleMessage(Message msg) {
AnySoftKeyboard ask = mKeyboard.get();
if (ask == null)//delayed posts and such may result in the reference gone
return;
switch (msg.what) {
case MSG_UPDATE_SUGGESTIONS:
ask.performUpdateSuggestions();
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment