Do not persist the source in memory when lazy parsing dependency info.
@@ -46,6 +46,7 @@ public class LazyParsedDependencyInfo extends DependencyInfo.Base {
public ImmutableMap<String, String> getLoadFlags() {
if (loadFlags == null) {
Map<String, String> loadFlagsBuilder = new TreeMap<>();
+ boolean hadSourceInMemory = ast.getSourceFile().hasSourceInMemory();
loadFlagsBuilder.putAll(delegate.getLoadFlags());
FeatureSet features = ast.getFeatures(compiler);
if (features.has(Feature.MODULES)) {
@@ -61,6 +62,10 @@ public class LazyParsedDependencyInfo extends DependencyInfo.Base {
}
loadFlags = ImmutableMap.copyOf(loadFlagsBuilder);
+ // Don't preserve the source in memory if it was loaded only for getLoadFlags().
+ if (!hadSourceInMemory) {
+ ast.getSourceFile().clearCachedSource();
+ }
// Don't preserve the full AST longer than necessary. It can consume a lot of memory.
ast = null;
}
