summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2012-06-07 13:23:48 +0000
committerBrian S. O'Neill <bronee@gmail.com>2012-06-07 13:23:48 +0000
commit23f363be862f76417d305b3b52dc23f2eab03119 (patch)
tree8d2c8753ef6e4fe3a9484a4e189d19830697bd5f /src/main/java/com/amazon/carbonado
parentae2b23ebef3a5d4e77e43e135a7d210e91dc7952 (diff)
Allow layouts to be reclaimed.
Diffstat (limited to 'src/main/java/com/amazon/carbonado')
-rw-r--r--src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java
index d9fe3e2..681909a 100644
--- a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java
+++ b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java
@@ -18,6 +18,7 @@
package com.amazon.carbonado.raw;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Map;
@@ -931,15 +932,17 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S
* sharing.
*/
private static class LayoutKey {
- private final Layout mLayout;
+ private final WeakReference<Layout> mLayoutRef;
+ private final int mHashCode;
LayoutKey(Layout layout) {
- mLayout = layout;
+ mLayoutRef = new WeakReference<Layout>(layout);
+ mHashCode = layout.getStorableTypeName().hashCode() * 7 + layout.getGeneration();
}
@Override
public int hashCode() {
- return mLayout.getStorableTypeName().hashCode() * 7 + mLayout.getGeneration();
+ return mHashCode;
}
@Override
@@ -948,12 +951,20 @@ public class GenericStorableCodec<S extends Storable> implements StorableCodec<S
return true;
}
if (obj instanceof LayoutKey) {
+ Layout layout = mLayoutRef.get();
+ if (layout == null) {
+ return false;
+ }
LayoutKey other = (LayoutKey) obj;
+ Layout otherLayout = other.mLayoutRef.get();
+ if (otherLayout == null) {
+ return false;
+ }
try {
- return mLayout.getStorableTypeName()
- .equals(other.mLayout.getStorableTypeName()) &&
- mLayout.getGeneration() == other.mLayout.getGeneration() &&
- mLayout.equalLayouts(other.mLayout);
+ return layout.getStorableTypeName()
+ .equals(otherLayout.getStorableTypeName()) &&
+ layout.getGeneration() == otherLayout.getGeneration() &&
+ layout.equalLayouts(otherLayout);
} catch (FetchException e) {
return false;
}