feat: free memory automatically (#5225)

This commit is contained in:
theanarkh 2026-01-19 06:39:52 +08:00 committed by GitHub
parent b12009a746
commit cd603fa981
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 163 additions and 0 deletions

View file

@ -0,0 +1,20 @@
import { EventEmitter } from 'events';
import { Session } from 'inspector';
const session = new Session();
session.connect();
export function gc() {
session.post('HeapProfiler.collectGarbage');
}
export const event = new EventEmitter();
export class Finalizer<T> extends FinalizationRegistry<T> {
constructor(handler: (value: T) => void) {
super((value) => {
handler(value);
event.emit('gc');
});
}
}