summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/util
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-03-26 01:41:48 +0200
committerVaadin Code Review <review@vaadin.com>2013-04-03 06:25:29 +0000
commit3cc90e37d8abfa53d127691ae0b7641298d64fa2 (patch)
treece9106505ab71dca5560188c9e20b71fa2a09157 /server/src/com/vaadin/util
parent4c5c1e0cfeff1c7118ab3fffe4d45e0f1966d470 (diff)
downloadvaadin-framework-3cc90e37d8abfa53d127691ae0b7641298d64fa2.tar.gz
vaadin-framework-3cc90e37d8abfa53d127691ae0b7641298d64fa2.zip
Fixed minimal (empty hashmap) memory leak on redeploy (#9993)
Change-Id: I2b3f83220070f1f46730d956abb24ba9edf02f20
Diffstat (limited to 'server/src/com/vaadin/util')
-rw-r--r--server/src/com/vaadin/util/CurrentInstance.java35
1 files changed, 26 insertions, 9 deletions
diff --git a/server/src/com/vaadin/util/CurrentInstance.java b/server/src/com/vaadin/util/CurrentInstance.java
index a2cfd4fff7..60489d596e 100644
--- a/server/src/com/vaadin/util/CurrentInstance.java
+++ b/server/src/com/vaadin/util/CurrentInstance.java
@@ -68,6 +68,10 @@ public class CurrentInstance implements Serializable {
@Override
protected Map<Class<?>, CurrentInstance> childValue(
Map<Class<?>, CurrentInstance> parentValue) {
+ if (parentValue == null) {
+ return null;
+ }
+
Map<Class<?>, CurrentInstance> value = new HashMap<Class<?>, CurrentInstance>();
// Copy all inheritable values to child map
@@ -79,11 +83,6 @@ public class CurrentInstance implements Serializable {
return value;
}
-
- @Override
- protected Map<java.lang.Class<?>, CurrentInstance> initialValue() {
- return new HashMap<Class<?>, CurrentInstance>();
- }
};
private CurrentInstance(Object instance, boolean inheritable) {
@@ -100,7 +99,11 @@ public class CurrentInstance implements Serializable {
* if there is no current instance.
*/
public static <T> T get(Class<T> type) {
- CurrentInstance currentInstance = instances.get().get(type);
+ Map<Class<?>, CurrentInstance> map = instances.get();
+ if (map == null) {
+ return null;
+ }
+ CurrentInstance currentInstance = map.get(type);
if (currentInstance != null) {
return type.cast(currentInstance.instance);
} else {
@@ -142,11 +145,25 @@ public class CurrentInstance implements Serializable {
}
private static <T> void set(Class<T> type, T instance, boolean inheritable) {
+ Map<Class<?>, CurrentInstance> map = instances.get();
if (instance == null) {
- instances.get().remove(type);
+ // remove the instance
+ if (map == null) {
+ return;
+ }
+ map.remove(type);
+ if (map.isEmpty()) {
+ instances.remove();
+ map = null;
+ }
} else {
assert type.isInstance(instance) : "Invald instance type";
- CurrentInstance previousInstance = instances.get().put(type,
+ if (map == null) {
+ map = new HashMap<Class<?>, CurrentInstance>();
+ instances.set(map);
+ }
+
+ CurrentInstance previousInstance = map.put(type,
new CurrentInstance(instance, inheritable));
if (previousInstance != null) {
assert previousInstance.inheritable == inheritable : "Inheritable status mismatch for "
@@ -163,7 +180,7 @@ public class CurrentInstance implements Serializable {
* Clears all current instances.
*/
public static void clearAll() {
- instances.get().clear();
+ instances.remove();
}
/**