Release statement source upon Effective Model completion 66/87466/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Feb 2020 19:50:53 +0000 (20:50 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 6 Feb 2020 10:10:33 +0000 (10:10 +0000)
Once we have an effective model, we do not need to access statement
source, hence we can let it be GC'd.

JIRA: YANGTOOLS-652
Change-Id: I5c7024c4709a7b97bf061cd5f02d923319378011
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 44bf1c0b678debcbd3066ca392a8bb08af54a4d8)

yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java

index c6c51f301a7268614b8792016088a71065383ce9..59d7be7495ef8b9ddbd87eca45d475b83742351e 100644 (file)
@@ -76,7 +76,9 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     private final QNameToStatementDefinitionMap qnameToStmtDefMap = new QNameToStatementDefinitionMap();
     private final PrefixToModuleMap prefixToModuleMap = new PrefixToModuleMap();
     private final BuildGlobalContext currentContext;
-    private final StatementStreamSource source;
+
+    // Freed as soon as we complete ModelProcessingPhase.EFFECTIVE_MODEL
+    private StatementStreamSource source;
 
     /*
      * "imported" namespaces in this source -- this points to RootStatementContexts of
@@ -307,8 +309,12 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
         if (phaseCompleted && currentPhaseModifiers.isEmpty()) {
             finishedPhase = phase;
             LOG.debug("Source {} finished phase {}", source, phase);
+            if (phase == ModelProcessingPhase.EFFECTIVE_MODEL) {
+                // We have the effective model acquired, which is the final phase of source interaction.
+                LOG.trace("Releasing source {}", source);
+                source = null;
+            }
             return PhaseCompletionProgress.FINISHED;
-
         }
 
         return hasProgressed ? PhaseCompletionProgress.PROGRESS : PhaseCompletionProgress.NO_PROGRESS;