15
15
*/
16
16
package com .diffplug .spotless .extra ;
17
17
18
- import static com .diffplug .spotless .extra .LibExtraPreconditions .requireElementsNonNull ;
19
-
20
18
import java .io .File ;
21
19
import java .io .FileInputStream ;
22
20
import java .io .IOException ;
@@ -78,8 +76,8 @@ public static LineEnding.Policy create(File projectDir, Supplier<Iterable<File>>
78
76
static class RelocatablePolicy extends LazyForwardingEquality <CachedEndings > implements LineEnding .Policy {
79
77
private static final long serialVersionUID = 5868522122123693015L ;
80
78
81
- final transient File projectDir ;
82
- final transient Supplier <Iterable <File >> toFormat ;
79
+ transient File projectDir ;
80
+ transient Supplier <Iterable <File >> toFormat ;
83
81
84
82
RelocatablePolicy (File projectDir , Supplier <Iterable <File >> toFormat ) {
85
83
this .projectDir = Objects .requireNonNull (projectDir , "projectDir" );
@@ -88,8 +86,13 @@ static class RelocatablePolicy extends LazyForwardingEquality<CachedEndings> imp
88
86
89
87
@ Override
90
88
protected CachedEndings calculateState () throws Exception {
91
- Runtime runtime = new RuntimeInit (projectDir , toFormat .get ()).atRuntime ();
92
- return new CachedEndings (projectDir , runtime , toFormat .get ());
89
+ Runtime runtime = new RuntimeInit (projectDir ).atRuntime ();
90
+ // LazyForwardingEquality guarantees that this will only be called once, and keeping toFormat
91
+ // causes a memory leak, see https://github.com/diffplug/spotless/issues/1194
92
+ CachedEndings state = new CachedEndings (projectDir , runtime , toFormat .get ());
93
+ projectDir = null ;
94
+ toFormat = null ;
95
+ return state ;
93
96
}
94
97
95
98
@ Override
@@ -146,8 +149,7 @@ static class RuntimeInit {
146
149
final @ Nullable File workTree ;
147
150
148
151
@ SuppressFBWarnings ("SIC_INNER_SHOULD_BE_STATIC_ANON" )
149
- RuntimeInit (File projectDir , Iterable <File > toFormat ) {
150
- requireElementsNonNull (toFormat );
152
+ RuntimeInit (File projectDir ) {
151
153
/////////////////////////////////
152
154
// USER AND SYSTEM-WIDE VALUES //
153
155
/////////////////////////////////
0 commit comments