Skip to content

Wrong disposable store used when onAfterModelAttached happens #192123

@jrieken

Description

@jrieken

onAfterModelAttached is called repeatedly and keeps adding a disposables to its lifecycle-dispoable

To repro

  • apply the patch below
  • start OSS and check the console for traces
lifecycle.js:250 MAYBE leak, _register used long time after create
_register @ lifecycle.js:250
onAfterModelAttached @ codeEditorContributions.js:92
setModel @ codeEditorWidget.js:318
setInput @ textResourceEditor.js:42
await in setInput (async)
setInput @ outputView.js:166
(anonymous) @ outputView.js:86
createCancelablePromise @ async.js:15
setInput @ outputView.js:86
showChannel @ outputView.js:35
onDidRegisterChannel @ outputServices.js:120
OutputService @ outputServices.js:68
_createInstance @ instantiationService.js:91
(anonymous) @ instantiationService.js:214
IdleValue._executor @ async.js:964
(anonymous) @ async.js:973
requestIdleCallback (async)
exports.runWhenIdle @ async.js:941
IdleValue @ async.js:973
_createServiceInstance @ instantiationService.js:213
_createServiceInstanceWithOwner @ instantiationService.js:191
_createServiceInstanceWithOwner @ instantiationService.js:194
_createAndCacheServiceInstance @ instantiationService.js:181
_safeCreateAndCacheServiceInstance @ instantiationService.js:132
_getOrCreateServiceInstance @ instantiationService.js:119
_createInstance @ instantiationService.js:72
createInstance @ instantiationService.js:62
DebugService @ debugService.js:58
_createInstance @ instantiationService.js:91
(anonymous) @ instantiationService.js:214
IdleValue._executor @ async.js:964
get value @ async.js:981
get @ instantiationService.js:250
CallStackEditorContribution @ callStackEditorContribution.js:113
_createInstance @ instantiationService.js:91
createInstance @ instantiationService.js:62
_instantiateById @ codeEditorContributions.js:126
_instantiateSome @ codeEditorContributions.js:104
(anonymous) @ codeEditorContributions.js:93
requestIdleCallback (async)
exports.runWhenIdle @ async.js:941
onAfterModelAttached @ codeEditorContributions.js:92
setModel @ codeEditorWidget.js:318
setInput @ textFileEditor.js:81

diff --git a/src/vs/base/common/lifecycle.ts b/src/vs/base/common/lifecycle.ts
index c044d998203..759d3c9d042 100644
--- a/src/vs/base/common/lifecycle.ts
+++ b/src/vs/base/common/lifecycle.ts
@@ -295,6 +295,8 @@ export abstract class Disposable implements IDisposable {
 
 	protected readonly _store = new DisposableStore();
 
+	private readonly _ts = Date.now();
+
 	constructor() {
 		trackDisposable(this);
 		setParentOfDisposable(this._store, this);
@@ -313,7 +315,12 @@ export abstract class Disposable implements IDisposable {
 		if ((o as unknown as Disposable) === this) {
 			throw new Error('Cannot register a disposable on itself!');
 		}
+		if (Date.now() - this._ts > 1000) {
+			console.trace('MAYBE leak, _register used long time after create');
+		}
+
 		return this._store.add(o);
+
 	}
 }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions