@@ -7,6 +7,7 @@ import type {Configuration} from 'webpack';
77import { DefinePlugin } from 'webpack' ;
88import type { Configuration as DevServerConfiguration } from 'webpack-dev-server' ;
99import { merge } from 'webpack-merge' ;
10+ import ForceGarbageCollectionPlugin from './ForceGarbageCollectionPlugin' ;
1011import type Environment from './types' ;
1112import getCommonConfiguration from './webpack.common' ;
1213
@@ -65,38 +66,7 @@ const getConfiguration = (environment: Environment): Promise<Configuration> =>
6566 'process.env.NODE_ENV' : JSON . stringify ( 'development' ) ,
6667 } ) ,
6768 new ReactRefreshWebpackPlugin ( { overlay : { sockProtocol : 'wss' } } ) ,
68- // Custom plugin to force garbage collection every 5 compilations
69- {
70- apply ( compiler ) {
71- let compilationCount = 0 ;
72- if ( gc && typeof gc === 'function' ) {
73- compiler . hooks . done . tap ( 'ForceGCEvery5Compilations' , ( ) => {
74- compilationCount ++ ;
75-
76- // Log memory usage every compilation
77- const memUsage = process . memoryUsage ( ) ;
78- const heapUsedMB = Math . round ( memUsage . heapUsed / 1024 / 1024 ) ;
79- const heapTotalMB = Math . round ( memUsage . heapTotal / 1024 / 1024 ) ;
80-
81- // eslint-disable-next-line no-console
82- console . log ( `📊 Compilation #${ compilationCount } - Heap: ${ heapUsedMB } MB/${ heapTotalMB } MB` ) ;
83-
84- if ( compilationCount % 5 === 0 ) {
85- // eslint-disable-next-line no-console
86- console . log ( `🗑️ Forcing garbage collection after ${ compilationCount } compilations` ) ;
87- // @ts -expect-error - gc is a global function provided by Node.js when --expose-gc is used
88- gc ( ) ;
89-
90- // Log memory after GC
91- const memAfterGC = process . memoryUsage ( ) ;
92- const heapAfterMB = Math . round ( memAfterGC . heapUsed / 1024 / 1024 ) ;
93- // eslint-disable-next-line no-console
94- console . log ( `✅ Post-GC heap: ${ heapAfterMB } MB (freed ${ heapUsedMB - heapAfterMB } MB)` ) ;
95- }
96- } ) ;
97- }
98- } ,
99- } ,
69+ new ForceGarbageCollectionPlugin ( ) ,
10070 ] ,
10171 // This prevents import error coming from react-native-tab-view/lib/module/TabView.js
10272 // where Pager is imported without extension due to having platform-specific implementations
0 commit comments