src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts/ResourceModelCollection/destroyReferencedObject
class ResourceModelCollection:	destroyReferencedObject(key: string, modelPromise: Promise<ITextEditorModel>): void {

		// untitled and inMemory are bound to a different lifecycle
		const resource = URI.parse(key);
		if (resource.scheme === Schemas.untitled || resource.scheme === Schemas.inMemory) {
			return;
		}

		// Track as being disposed before waiting for model to load
		// to handle the case that the reference is acquired again
		this.modelsToDispose.add(key);

		(async () => {
			try {
				const model = await modelPromise;

				if (!this.modelsToDispose.has(key)) {
					// return if model has been acquired again meanwhile
					return;
				}

				if (model instanceof TextFileEditorModel) {
					// text file models have conditions that prevent them
					// from dispose, so we have to wait until we can dispose
					await this.textFileService.files.canDispose(model);
				}

				if (!this.modelsToDispose.has(key)) {
					// return if model has been acquired again meanwhile
					return;
				}

				// Finally we can dispose the model
				model.dispose();
			} catch (error) {
				// ignore
			} finally {
				this.modelsToDispose.delete(key); // Untrack as being disposed
			}
		})();
	}