Skip to content

Commit 01d23fa

Browse files
authored
Fix memory leak in DotNet project wizard (#2067)
- Fix memory leak in DotNet project wizard by disposing the model - Remove an unnecessary dispose in the other SAM init paths ModuleRootModificationUtil#updateModel handles it. However, it seems ModuleRootModificationUti#updateModel does not work for our Rider case since it's a RootModel instead of a Model
1 parent 440d6ef commit 01d23fa

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/ui/wizard/SamProjectGeneratorIntelliJShims.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class SamProjectBuilder(private val generator: SamProjectGenerator) : ModuleBuil
6666
try {
6767
samTemplate.postCreationAction(settings, outputDir, model, generator.defaultSourceCreatingProject, indicator)
6868
} catch (t: Throwable) {
69-
LOG.error(t) { "Exception thrown during postCreationAction" }
70-
model.dispose()
69+
LOG.error(t) { "Exception thrown during postCreationAction!" }
7170
}
7271
}
7372
}

jetbrains-rider/src/software/aws/toolkits/jetbrains/ui/wizard/DotNetSamProjectGenerator.kt

+15-10
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,24 @@ class DotNetSamProjectGenerator(
194194
projectToClose = null,
195195
forceOpenInNewFrame = false,
196196
solutionFile = solutionFile
197-
)
197+
) ?: return
198+
198199
vcsPanel?.initRepository(project)
199200

200-
project ?: return
201201
val modifiableModel = ModuleManager.getInstance(project).modules.firstOrNull()?.rootManager?.modifiableModel ?: return
202-
val progressIndicator = if (progressManager.hasProgressIndicator()) progressManager.progressIndicator else DumbProgressIndicator()
203-
samSettings.template.postCreationAction(
204-
settings = samSettings,
205-
contentRoot = outDirVf,
206-
rootModel = modifiableModel,
207-
sourceCreatingProject = generator.defaultSourceCreatingProject,
208-
indicator = progressIndicator
209-
)
202+
try {
203+
val progressIndicator = if (progressManager.hasProgressIndicator()) progressManager.progressIndicator else DumbProgressIndicator()
204+
205+
samSettings.template.postCreationAction(
206+
settings = samSettings,
207+
contentRoot = outDirVf,
208+
rootModel = modifiableModel,
209+
sourceCreatingProject = generator.defaultSourceCreatingProject,
210+
indicator = progressIndicator
211+
)
212+
} finally {
213+
modifiableModel.dispose()
214+
}
210215
}
211216

212217
override fun refreshUI() {

0 commit comments

Comments
 (0)