diff options
author | joel.leitch@gmail.com <joel.leitch@gmail.com@2534bb62-2c4b-0410-85e8-b5006b95c4ae> | 2013-01-14 22:05:28 +0000 |
---|---|---|
committer | joel.leitch@gmail.com <joel.leitch@gmail.com@2534bb62-2c4b-0410-85e8-b5006b95c4ae> | 2013-01-14 22:05:28 +0000 |
commit | c54f1c3dbe116ef3bb703191216485766c9995cf (patch) | |
tree | 9f1a43333677868f1139f889fa86d2a298645184 | |
parent | 377380def0bdca5f917c7043262fd0cfc550e3fc (diff) | |
download | android_external_gson-c54f1c3dbe116ef3bb703191216485766c9995cf.tar.gz android_external_gson-c54f1c3dbe116ef3bb703191216485766c9995cf.tar.bz2 android_external_gson-c54f1c3dbe116ef3bb703191216485766c9995cf.zip |
Fix object leak from ThreadLocal.
git-svn-id: http://google-gson.googlecode.com/svn/trunk/gson@1223 2534bb62-2c4b-0410-85e8-b5006b95c4ae
-rw-r--r-- | src/main/java/com/google/gson/Gson.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/com/google/gson/Gson.java b/src/main/java/com/google/gson/Gson.java index 9dbbd3a7..ab63fdc0 100644 --- a/src/main/java/com/google/gson/Gson.java +++ b/src/main/java/com/google/gson/Gson.java @@ -335,9 +335,11 @@ public final class Gson { } Map<TypeToken<?>, FutureTypeAdapter<?>> threadCalls = calls.get(); + boolean requiresThreadLocalCleanup = false; if (threadCalls == null) { threadCalls = new HashMap<TypeToken<?>, FutureTypeAdapter<?>>(); calls.set(threadCalls); + requiresThreadLocalCleanup = true; } // the key and value type parameters always agree @@ -346,9 +348,10 @@ public final class Gson { return ongoingCall; } - FutureTypeAdapter<T> call = new FutureTypeAdapter<T>(); - threadCalls.put(type, call); try { + FutureTypeAdapter<T> call = new FutureTypeAdapter<T>(); + threadCalls.put(type, call); + for (TypeAdapterFactory factory : factories) { TypeAdapter<T> candidate = factory.create(this, type); if (candidate != null) { @@ -360,6 +363,10 @@ public final class Gson { throw new IllegalArgumentException("GSON cannot handle " + type); } finally { threadCalls.remove(type); + + if (requiresThreadLocalCleanup) { + calls.remove(); + } } } |