Leaking context in Android
In Java, non-static inner and anonymous classes hold an implicit reference to their outer class. Static inner classes, on the other hand, do not. Common examples of non-static inner and anonymous classes are Handler and Runnable.
When the life-cycle of your instance is more than that of Activity, due to the implicit reference, the Activity won't get garbage collected causing a memory leak.
To fix this, make your instance static and hold a weak reference to the enclosing Activity if you want to call its methods. The same holds true for Fragments.
Written by Mustafa Ali
Related protips
1 Response
Another way of doing it would be to use: http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/InstanceCreator.html
example: https://sites.google.com/site/gson/gson-user-guide#TOC-Using-Gson
I wouldn't use it, but there it is.