Using --expose-gc for TypeScript with ts-node or tsx

79 Views Asked by At

Neither ts-node nor tsx seem to support the --expose-gc flag, so the garbage collector object global.gc is always undefined. How am I supposed to clean up memory in my TypeScript code?

1

There are 1 best solutions below

0
Jo Liss On

ts-node

Pull request #536 seems to have removed Node flags like --expose-gc, but it recommends that you do this instead:

node -r 'ts-node/register' --expose-gc file.ts

tsx

The --expose-gc flag does seem to be supported by tsx:

tsx --expose-gc file.ts