Memory
Optimization
Manual memory optimization and garbage collection in AxilJS with the optimizer and GC helpers.
On this page3
Optimize
TypeScript
TS
1import { optimizer } from '@axiljs/memory'
2
3const result = await optimizer.optimize()
4result.freedMb
5result.gcTriggered
6result.actions // string[] describing what was doneoptimize() triggers GC, prunes tracked caches above 90% of their maxSize down to 70%, then triggers GC again.
Module cache clearing (opt-in)
TypeScript
TS
1import { MemoryOptimizer } from '@axiljs/memory'
2
3await new MemoryOptimizer({ clearModuleCache: true }).optimize()
4// or per call
5await optimizer.optimize({ clearModuleCache: true })Warning
clearModuleCache defaults to false. Dropping require.cache entries makes a later require() re-evaluate the module, which can duplicate singletons and break instanceof.
GC
TypeScript
TS
1import { triggerGC, triggerGCAsync, isGCAvailable, gcTip } from '@axiljs/memory'
2
3if (isGCAvailable()) triggerGC() // returns false when GC is not exposed
4await triggerGCAsync() // triggers GC and waits 100 ms
5console.log(gcTip())Enable with: node --expose-gc dist/main.js
Was this page helpful?