Skip to content

Commit

Permalink
chore - remove listener "GC'ed before dispose" tracking because we no…
Browse files Browse the repository at this point in the history
…w have this for all disposables (microsoft#237656)
  • Loading branch information
jrieken authored Jan 10, 2025
1 parent 672240b commit 88e6fac
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions src/vs/base/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ import { IObservable, IObservableWithChange, IObserver } from './observable.js';
import { StopWatch } from './stopwatch.js';
import { MicrotaskDelay } from './symbols.js';

// -----------------------------------------------------------------------------------------------------------------------
// Uncomment the next line to print warnings whenever a listener is GC'ed without having been disposed. This is a LEAK.
// -----------------------------------------------------------------------------------------------------------------------
const _enableListenerGCedWarning = false
// || Boolean("TRUE") // causes a linter warning so that it cannot be pushed
;

// -----------------------------------------------------------------------------------------------------------------------
// Uncomment the next line to print warnings whenever an emitter with listeners is disposed. That is a sign of code smell.
Expand Down Expand Up @@ -984,28 +978,6 @@ const forEachListener = <T>(listeners: ListenerOrListeners<T>, fn: (c: ListenerC
}
};


let _listenerFinalizers: FinalizationRegistry<string> | undefined;

if (_enableListenerGCedWarning) {
const leaks: string[] = [];

setInterval(() => {
if (leaks.length === 0) {
return;
}
console.warn('[LEAKING LISTENERS] GC\'ed these listeners that were NOT yet disposed:');
console.warn(leaks.join('\n'));
leaks.length = 0;
}, 3000);

_listenerFinalizers = new FinalizationRegistry(heldValue => {
if (typeof heldValue === 'string') {
leaks.push(heldValue);
}
});
}

/**
* The Emitter can be used to expose an Event to the public
* to fire it from the insides.
Expand Down Expand Up @@ -1161,7 +1133,6 @@ export class Emitter<T> {


const result = toDisposable(() => {
_listenerFinalizers?.unregister(result);
removeMonitor?.();
this._removeListener(contained);
});
Expand All @@ -1171,12 +1142,6 @@ export class Emitter<T> {
disposables.push(result);
}

if (_listenerFinalizers) {
const stack = new Error().stack!.split('\n').slice(2, 3).join('\n').trim();
const match = /(file:|vscode-file:\/\/vscode-app)?(\/[^:]*:\d+:\d+)/.exec(stack);
_listenerFinalizers.register(result, match?.[2] ?? stack, result);
}

return result;
};

Expand Down

0 comments on commit 88e6fac

Please sign in to comment.