napi-rs/memory-testing/tsfn.mjs

23 lines
513 B
JavaScript
Raw Permalink Normal View History

import { createRequire } from 'module'
import { setTimeout } from 'timers/promises'
import { displayMemoryUsageFromNode } from './util.mjs'
const initialMemoryUsage = process.memoryUsage()
const require = createRequire(import.meta.url)
const api = require(`./index.node`)
let i = 1
// eslint-disable-next-line no-constant-condition
while (true) {
api.leakingFunc(() => {})
if (i % 100000 === 0) {
await setTimeout(100)
global.gc?.()
displayMemoryUsageFromNode(initialMemoryUsage)
}
i++
}