void () { Disposable uiDisposable = PlatformDataKeys.UI_DISPOSABLE.getData(DataManager.getInstance().getDataContext(this)); if (uiDisposable != null) { // If this component is added to a dialog (for example, the settings dialog), // then we have to release the editor simultaneously on close. // Otherwise, a corresponding dynamic plugin cannot be unloaded. Disposer.register(uiDisposable, this::releaseEditorNow); } myDisposable = Disposer.newDisposable("ETF dispose"); Disposer.register(myDisposable, this::releaseEditorLater); Project project = getProjectIfValid(); if (project != null) { project.getMessageBus().connect(myDisposable).subscribe(ProjectCloseListener.TOPIC, new ProjectCloseListener() { @Override public void projectClosing(@NotNull Project p) { if (p == project) { releaseEditorNow(); } } }); } Disposer.register(myDisposable, () -> { // remove traces of this editor from UndoManager to avoid leaks Document document = myDocument; if (document != null) { if (project != null && !project.isDisposed()) { ((UndoManagerImpl)UndoManager.getInstance(project)).clearDocumentReferences(document); } ((UndoManagerImpl)UndoManager.getGlobalInstance()).clearDocumentReferences(document); } }); }