From d96e0acd836e3e8b40740c3494b0d58c19630feb Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Fri, 31 May 2024 23:35:30 +0300 Subject: [PATCH] fix memory leaks --- .../kotlin/org/move/cli/MoveProjectsService.kt | 8 ++++++-- .../org/move/cli/MoveProjectsSyncTask.kt | 6 +++--- .../org/move/cli/PluginProjectDisposable.kt | 4 ++++ .../MvExternalLinterConfigurable.kt | 18 +----------------- .../cli/settings/PerProjectMoveConfigurable.kt | 14 ++++++++------ 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/org/move/cli/MoveProjectsService.kt b/src/main/kotlin/org/move/cli/MoveProjectsService.kt index 7bf48082d..1ef9a94c1 100644 --- a/src/main/kotlin/org/move/cli/MoveProjectsService.kt +++ b/src/main/kotlin/org/move/cli/MoveProjectsService.kt @@ -216,9 +216,13 @@ class MoveProjectsService(val project: Project): Disposable { ): CompletableFuture> { val refreshStatusPublisher = project.messageBus.syncPublisher(MOVE_PROJECTS_REFRESH_TOPIC) + val syncOnRefreshTopic = { + project.messageBus.takeIf { !it.isDisposed } + ?.syncPublisher(MOVE_PROJECTS_REFRESH_TOPIC) + } val wrappedModifyProjects = { projects: List -> - refreshStatusPublisher.onRefreshStarted() + syncOnRefreshTopic()?.onRefreshStarted() modifyProjects(projects) } return projects.updateAsync(wrappedModifyProjects) @@ -247,7 +251,7 @@ class MoveProjectsService(val project: Project): Disposable { } .handle { projects, err -> val status = err?.toRefreshStatus() ?: MoveRefreshStatus.SUCCESS - refreshStatusPublisher.onRefreshFinished(status) + syncOnRefreshTopic()?.onRefreshFinished(status) projects } } diff --git a/src/main/kotlin/org/move/cli/MoveProjectsSyncTask.kt b/src/main/kotlin/org/move/cli/MoveProjectsSyncTask.kt index 61c1dac80..6efc2d482 100644 --- a/src/main/kotlin/org/move/cli/MoveProjectsSyncTask.kt +++ b/src/main/kotlin/org/move/cli/MoveProjectsSyncTask.kt @@ -323,11 +323,11 @@ private class SyncProcessAdapter( override fun onTextAvailable(event: ProcessEvent, outputType: Key) { val text = event.text.trim { it <= ' ' } if (text.startsWith("FETCHING GIT DEPENDENCY")) { - val git = text.substring("FETCHING GIT DEPENDENCY ".length) - context.withProgressText("Fetching $git") + val gitRepo = text.substring("FETCHING GIT DEPENDENCY".length) + context.withProgressText("Fetching $gitRepo") } if (text.startsWith("UPDATING GIT DEPENDENCY")) { - val gitRepo = text.substring("UPDATING GIT DEPENDENCY ".length) + val gitRepo = text.substring("UPDATING GIT DEPENDENCY".length) context.withProgressText("Updating $gitRepo") } } diff --git a/src/main/kotlin/org/move/cli/PluginProjectDisposable.kt b/src/main/kotlin/org/move/cli/PluginProjectDisposable.kt index f9545863a..9ae448c90 100644 --- a/src/main/kotlin/org/move/cli/PluginProjectDisposable.kt +++ b/src/main/kotlin/org/move/cli/PluginProjectDisposable.kt @@ -7,10 +7,14 @@ import com.intellij.openapi.components.Service class PluginProjectDisposable : Disposable { override fun dispose() { } + + override fun toString(): String = "APTOS_PROJECT_DISPOSABLE" } @Service(Service.Level.APP) class PluginApplicationDisposable : Disposable { override fun dispose() { } + + override fun toString(): String = "APTOS_PLUGIN_DISPOSABLE" } \ No newline at end of file diff --git a/src/main/kotlin/org/move/cli/externalLinter/MvExternalLinterConfigurable.kt b/src/main/kotlin/org/move/cli/externalLinter/MvExternalLinterConfigurable.kt index 341160f46..867c63577 100644 --- a/src/main/kotlin/org/move/cli/externalLinter/MvExternalLinterConfigurable.kt +++ b/src/main/kotlin/org/move/cli/externalLinter/MvExternalLinterConfigurable.kt @@ -19,13 +19,6 @@ class MvExternalLinterConfigurable(val project: Project): BoundConfigurable("Ext RsCommandLineEditor(project, RsCommandLineEditor.EmptyTextFieldCompletionProvider()) // RsCommandLineEditor(project, CargoCommandCompletionProvider(project.cargoProjects, "check ") { null }) -// private val channelLabel: JLabel = Label(RsBundle.message("settings.rust.external.linters.channel.label")) -// private val channel: ComboBox = ComboBox().apply { -// RustChannel.values() -// .sortedBy { it.index } -// .forEach { addItem(it) } -// } - private val environmentVariables: EnvironmentVariablesComponent = EnvironmentVariablesComponent() override fun createPanel(): DialogPanel = panel { @@ -47,15 +40,6 @@ class MvExternalLinterConfigurable(val project: Project): BoundConfigurable("Ext componentSet = { component, value -> component.text = value }, prop = state::additionalArguments.toMutableProperty() ) - -// channelLabel.labelFor = channel -// cell(channelLabel) -// cell(channel) -// .bind( -// componentGet = { it.item }, -// componentSet = { component, value -> component.item = value }, -// prop = state::channel.toMutableProperty() -// ) } row(environmentVariables.label) { @@ -75,7 +59,7 @@ class MvExternalLinterConfigurable(val project: Project): BoundConfigurable("Ext separator() row { checkBox("Prevent duplicate errors") - .comment("Skips errors which are implemented by the IDE own analysis engine") + .comment("Skips errors which are implemented by the IDE's own analysis engine") .bindSelected(state::skipErrorsKnownToIde) } diff --git a/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt b/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt index 550d30264..3b8c7810a 100644 --- a/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt +++ b/src/main/kotlin/org/move/cli/settings/PerProjectMoveConfigurable.kt @@ -7,17 +7,17 @@ import com.intellij.openapi.ui.DialogPanel import com.intellij.openapi.util.Disposer import com.intellij.ui.components.JBRadioButton import com.intellij.ui.dsl.builder.* -import com.intellij.ui.layout.ComponentPredicate import org.move.cli.settings.aptos.ChooseAptosCliPanel import org.move.cli.settings.sui.ChooseSuiCliPanel import org.move.openapiext.showSettingsDialog +// panels needs not to be bound to the Configurable itself, as it's sometimes created without calling the `createPanel()` class PerProjectMoveConfigurable(val project: Project): BoundConfigurable("Move Language") { - private val chooseAptosCliPanel = ChooseAptosCliPanel(versionUpdateListener = null) - private val chooseSuiCliPanel = ChooseSuiCliPanel() - override fun createPanel(): DialogPanel { + val chooseAptosCliPanel = ChooseAptosCliPanel(versionUpdateListener = null) + val chooseSuiCliPanel = ChooseSuiCliPanel() + val configurablePanel = panel { val settings = project.moveSettings @@ -136,8 +136,10 @@ class PerProjectMoveConfigurable(val project: Project): BoundConfigurable("Move || suiPanelData.localSuiPath != settings.localSuiPath } } - Disposer.register(this.disposable!!, chooseAptosCliPanel) - Disposer.register(this.disposable!!, chooseSuiCliPanel) + this.disposable?.let { + Disposer.register(it, chooseAptosCliPanel) + Disposer.register(it, chooseSuiCliPanel) + } return configurablePanel }