diff --git a/src/main/java/org/commcare/cases/instance/StorageBackedChildElement.java b/src/main/java/org/commcare/cases/instance/StorageBackedChildElement.java index cfdec35a5..738671c7a 100644 --- a/src/main/java/org/commcare/cases/instance/StorageBackedChildElement.java +++ b/src/main/java/org/commcare/cases/instance/StorageBackedChildElement.java @@ -200,6 +200,7 @@ public TreeReference getRef() { @Override public void clearVolatiles() { + // we should also clear the other cache implementation in this class in future ref = null; } diff --git a/src/main/java/org/javarosa/core/model/FormDef.java b/src/main/java/org/javarosa/core/model/FormDef.java index 8d1604f8c..30b86e31b 100755 --- a/src/main/java/org/javarosa/core/model/FormDef.java +++ b/src/main/java/org/javarosa/core/model/FormDef.java @@ -373,7 +373,7 @@ public FormIndex deleteRepeat(FormIndex index) { reduceTreeSiblingMultiplicities(parentElement, deleteElement); - this.getMainInstance().cleanCache(parentElement); + this.getMainInstance().cleanCache(); triggerTriggerables(deleteRef); return newIndex; diff --git a/src/main/java/org/javarosa/core/model/instance/ConcreteTreeElement.java b/src/main/java/org/javarosa/core/model/instance/ConcreteTreeElement.java index 9687f6fc0..4acd848a8 100644 --- a/src/main/java/org/javarosa/core/model/instance/ConcreteTreeElement.java +++ b/src/main/java/org/javarosa/core/model/instance/ConcreteTreeElement.java @@ -340,6 +340,16 @@ public TreeReference getRef() { @Override public void clearVolatiles() { refCache = null; + if (children != null) { + for (T child : children) { + child.clearVolatiles(); + } + } + if (attributes != null) { + for (T attribute : attributes) { + attribute.clearVolatiles(); + } + } } @Override diff --git a/src/main/java/org/javarosa/core/model/instance/DataInstance.java b/src/main/java/org/javarosa/core/model/instance/DataInstance.java index b61a8b236..724f2e7cd 100644 --- a/src/main/java/org/javarosa/core/model/instance/DataInstance.java +++ b/src/main/java/org/javarosa/core/model/instance/DataInstance.java @@ -289,30 +289,11 @@ public void setCacheHost(CacheHost cacheHost) { this.mCacheHost = cacheHost; } - public void cleanCache() { - cleanCache(getBase()); - } - /** * Cleans reference caches maintained by the instance and TreeElements contained in the contextNode - * @param contextNode Parent node inside the scope of which we clear the TreeElement volatiles */ - public void cleanCache(AbstractTreeElement contextNode) { + public void cleanCache() { referenceCache.clear(); - cleanTreeElementCache(contextNode); - } - - /** - * Loops through the node and it's children and clears their volatiles - * @param contextNode Parent node inside the scope of which we clear the TreeElement volatiles - */ - private void cleanTreeElementCache(AbstractTreeElement contextNode) { - if (contextNode == null) { - return; - } - contextNode.clearVolatiles(); - for (int i = 0; i < contextNode.getNumChildren(); i++) { - cleanTreeElementCache(contextNode.getChildAt(i)); - } + getBase().clearVolatiles(); } } diff --git a/src/main/java/org/javarosa/core/model/instance/InstanceBase.java b/src/main/java/org/javarosa/core/model/instance/InstanceBase.java index 1cf7cdcf7..c24e042d9 100644 --- a/src/main/java/org/javarosa/core/model/instance/InstanceBase.java +++ b/src/main/java/org/javarosa/core/model/instance/InstanceBase.java @@ -143,7 +143,9 @@ public TreeReference getRef() { @Override public void clearVolatiles() { - // nothing to clear + if (child != null) { + child.clearVolatiles(); + } } @Override diff --git a/src/main/java/org/javarosa/core/model/instance/TreeElement.java b/src/main/java/org/javarosa/core/model/instance/TreeElement.java index 420fefab0..11c777119 100755 --- a/src/main/java/org/javarosa/core/model/instance/TreeElement.java +++ b/src/main/java/org/javarosa/core/model/instance/TreeElement.java @@ -856,6 +856,16 @@ public String getNamespace() { @Override public void clearVolatiles() { refCache[0] = null; + if (children != null) { + for (TreeElement child : children) { + child.clearVolatiles(); + } + } + if (attributes != null) { + for (TreeElement attribute : attributes) { + attribute.clearVolatiles(); + } + } } public void setNamespace(String namespace) {