@@ -141,6 +141,61 @@ describe("MultiCompiler", () => {
141141 } ) ;
142142 } ) ;
143143
144+ it ( "should release per-child compilation memory as each child finishes (#15521)" , ( done ) => {
145+ const compiler = createMultiCompiler ( ) ;
146+ compiler . run ( ( err , stats ) => {
147+ if ( err ) return done ( err ) ;
148+ for ( const childStats of stats . stats ) {
149+ const compilation = childStats . compilation ;
150+ // codeGenerationResults: only used during seal/emit, dropped.
151+ expect ( compilation . codeGenerationResults . map . size ) . toBe ( 0 ) ;
152+ // Stats must still be usable on the slimmed compilation.
153+ expect ( typeof childStats . toJson ( ) . hash ) . toBe ( "string" ) ;
154+ }
155+ compiler . close ( done ) ;
156+ } ) ;
157+ } ) ;
158+
159+ it ( "should release a finished child's codeGenerationResults before a dependent sibling runs (#15521)" , ( done ) => {
160+ const compiler = webpack (
161+ Object . assign (
162+ [
163+ {
164+ name : "a" ,
165+ context : path . join ( __dirname , "fixtures" ) ,
166+ entry : "./a.js"
167+ } ,
168+ {
169+ name : "b" ,
170+ context : path . join ( __dirname , "fixtures" ) ,
171+ entry : "./b.js" ,
172+ dependencies : [ "a" ]
173+ }
174+ ] ,
175+ { parallelism : 1 }
176+ )
177+ ) ;
178+ compiler . outputFileSystem = createFsFromVolume ( new Volume ( ) ) ;
179+ compiler . watchFileSystem = { watch ( _a , _b , _c , _d , _e , _f , _g ) { } } ;
180+ const [ a , b ] = compiler . compilers ;
181+ let aCompilation ;
182+ a . hooks . done . tap ( "test" , ( stats ) => {
183+ aCompilation = stats . compilation ;
184+ } ) ;
185+ // With dependencies + parallelism 1, b only starts after a is fully
186+ // done (including a's afterDone release tap). Capture a's map size at
187+ // that point: it must already be cleared while b is about to build.
188+ let aMapSizeWhenBStarts ;
189+ b . hooks . run . tap ( "test" , ( ) => {
190+ aMapSizeWhenBStarts = aCompilation . codeGenerationResults . map . size ;
191+ } ) ;
192+ compiler . run ( ( err ) => {
193+ if ( err ) return done ( err ) ;
194+ expect ( aMapSizeWhenBStarts ) . toBe ( 0 ) ;
195+ compiler . close ( done ) ;
196+ } ) ;
197+ } ) ;
198+
144199 it ( "should watch again correctly after first compilation" , ( done ) => {
145200 const compiler = createMultiCompiler ( ) ;
146201 compiler . run ( ( err , _stats ) => {
0 commit comments