From 06b8fea422ef8eaa5d7da83eeac31a142db8106e Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Wed, 30 Oct 2019 14:08:10 +0100 Subject: [PATCH] Ensures IncrementalTransformationSynchronizer cleanup on project close When a project is closed where an IncrementalTransformationSynchronizer was initialized, and for an error a reference to the project was kept, the WeakHashMap entry for the synchronizers were not removed, resulting in the query engine being kept in memory. This change ensures that even in such erroneous cases the engine is disposed by explicitly calling a remove call before a project is closed. --- .../src/main/com/incquerylabs/v4md/V4MDPlugin.java | 2 ++ .../IncrementalTransformationSynchronizer.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/V4MDPlugin.java b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/V4MDPlugin.java index 1f211fa..53b3046 100644 --- a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/V4MDPlugin.java +++ b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/V4MDPlugin.java @@ -2,6 +2,7 @@ import com.incquerylabs.v4md.expressions.BinaryVQLExpression; import com.incquerylabs.v4md.internal.IProjectChangedListener; +import com.incquerylabs.v4md.transformations.IncrementalTransformationSynchronizer; import com.nomagic.ci.persistence.IProject; import com.nomagic.magicdraw.core.Application; import com.nomagic.magicdraw.core.Project; @@ -18,6 +19,7 @@ private final class V4MDProjectListener extends ProjectEventListenerAdapter impl @Override public void projectPreClosed(Project project) { // There is no need to explicitly initialize adapters; the dispose handles uninitialized adapters correctly + IncrementalTransformationSynchronizer.disposeSynchronizer(project); ViatraQueryAdapter.disposeAdapter(project); } diff --git a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/transformations/IncrementalTransformationSynchronizer.java b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/transformations/IncrementalTransformationSynchronizer.java index f9cde9f..048900c 100644 --- a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/transformations/IncrementalTransformationSynchronizer.java +++ b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/transformations/IncrementalTransformationSynchronizer.java @@ -56,6 +56,10 @@ private ViatraTransformationSynchronizerManager() { public ModelSynchronizer apply(Project t) { return (ModelSynchronizer) storage.computeIfAbsent(t, IncrementalTransformationSynchronizer::new); } + + } + public static void disposeSynchronizer(Project p) { + ((ViatraTransformationSynchronizerManager)FACTORY).storage.remove(p); } private BatchTransformation transformation;