Release statement source upon Effective Model completion 68/87468/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Feb 2020 19:50:53 +0000 (20:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Feb 2020 10:30:01 +0000 (11:30 +0100)
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>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java

index 648aae7cdbb11bbc00c07cca0a1d3fbb56799fa5..b15b3f63a8e8051a6804a49412808dccc34124ff 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;