Reduce SchemaContext cache to weak values 44/12844/1
authorRobert Varga <rovarga@cisco.com>
Fri, 14 Nov 2014 13:32:06 +0000 (14:32 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 14 Nov 2014 13:32:06 +0000 (14:32 +0100)
While constructing a SchemaContext is potentially costly, we do not need
to retain them if they are not used for long periods of time. Soft
references attempt to retain the context until the memory pressure is
pretty high, while weak references are cleared as soon as the object is
proven to be weakly reachable.

Change-Id: I2df2a78218d3b439edadda2192ff541e4c1c0fee
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java

index e6e357dc0e9664f21595bf54066caea591071500..ebe602d5a72c42a06fec63899b8d63a0d8b9d2ce 100644 (file)
@@ -63,7 +63,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
             return repository.getSchemaSource(input, ASTSchemaSource.class);
         }
     };
-    private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().softValues().build();
+    private final Cache<Collection<SourceIdentifier>, SchemaContext> cache = CacheBuilder.newBuilder().weakValues().build();
 
     private final AsyncFunction<List<ASTSchemaSource>, SchemaContext> assembleSources = new AsyncFunction<List<ASTSchemaSource>, SchemaContext>() {
         @Override