feat: free memory automatically (#5225)
This commit is contained in:
parent
b12009a746
commit
cd603fa981
9 changed files with 163 additions and 0 deletions
20
lib/binding_web/test/memory.ts
Normal file
20
lib/binding_web/test/memory.ts
Normal 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');
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue