From: Marko Luukkainen Date: Fri, 5 Feb 2021 15:05:35 +0000 (+0200) Subject: Improved clearing of CanvasContext X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=197f65594b46aaa087ac4d9bb6cb5514376377ca;p=simantics%2Fplatform.git Improved clearing of CanvasContext gitlab #674 Change-Id: Ib2e6d13346576f6852f30fa31c08adc0b638db13 --- diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/impl/CanvasContext.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/impl/CanvasContext.java index 998b8a9a2..cf9cff75c 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/impl/CanvasContext.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/impl/CanvasContext.java @@ -191,6 +191,7 @@ public class CanvasContext extends Context implements ICanva } // HN: added to decrease memory leaks eventHandlerStack = null; + hintStack.clear(); hintStack = null; canvasNode.cleanup(); canvasNode = null; diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/AbstractHintObservable.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/AbstractHintObservable.java index aacadc1a6..bbe2447c9 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/AbstractHintObservable.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/AbstractHintObservable.java @@ -255,5 +255,10 @@ public abstract class AbstractHintObservable implements IHintObservable { list.remove(threadAccess, listener); if (list.isEmpty()) keyListeners.remove(key); } + + public void clear() { + keyListeners.clear(); + listeners.clear(); + } } diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/HintStack.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/HintStack.java index 2be216d30..d6af390e6 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/HintStack.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/hints/HintStack.java @@ -333,4 +333,9 @@ public class HintStack extends AbstractHintObservable implements IHintStack { }}; } + public void clear() { + super.clear(); + stack.clear(); + } + } diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/prioritystack/PriorityStack.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/prioritystack/PriorityStack.java index 81029105d..6c0a36acd 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/prioritystack/PriorityStack.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/prioritystack/PriorityStack.java @@ -197,5 +197,15 @@ public class PriorityStack implements IPriorityStack { public String toString() { return EString.implode(snapshotArray, "\n"); } + + public void clear() { + if (list != null) { + list.clear(); + } + if (listeners != null) { + listeners.clear(); + } + snapshotArray = createArray(0); + } }