Skip to content

Commit

Permalink
Ensures IncrementalTransformationSynchronizer cleanup on project close
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ujhelyiz committed Nov 5, 2019
1 parent faddc1f commit 06b8fea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 06b8fea

Please sign in to comment.