trim nodes_status: avoid potential memory leak;
authorwenzelm
Sat, 18 Aug 2018 13:52:12 +0200
changeset 68761 8bb51b3de39f
parent 68760 0626cae56b6f
child 68762 8750edd967ce
trim nodes_status: avoid potential memory leak;
src/Pure/PIDE/document_status.scala
src/Tools/jEdit/src/theories_dockable.scala
--- a/src/Pure/PIDE/document_status.scala	Sat Aug 18 13:40:23 2018 +0200
+++ b/src/Pure/PIDE/document_status.scala	Sat Aug 18 13:52:12 2018 +0200
@@ -185,6 +185,9 @@
     def + (entry: (Document.Node.Name, Node_Status)): Nodes_Status =
       new Nodes_Status(rep + entry)
 
+    def restrict(domain: Set[Document.Node.Name]): Nodes_Status =
+      new Nodes_Status(rep -- rep.keysIterator.filterNot(domain))
+
     override def hashCode: Int = rep.hashCode
     override def equals(that: Any): Boolean =
       that match {
--- a/src/Tools/jEdit/src/theories_dockable.scala	Sat Aug 18 13:40:23 2018 +0200
+++ b/src/Tools/jEdit/src/theories_dockable.scala	Sat Aug 18 13:52:12 2018 +0200
@@ -210,7 +210,9 @@
   }
   status.renderer = new Node_Renderer
 
-  private def handle_update(restriction: Option[Set[Document.Node.Name]] = None)
+  private def handle_update(
+    restriction: Option[Set[Document.Node.Name]] = None,
+    trim: Boolean = false)
   {
     GUI_Thread.require {}
 
@@ -230,8 +232,11 @@
             }
         })
 
-    if (nodes_status != nodes_status1) {
-      nodes_status = nodes_status1
+    val nodes_status2 =
+      if (trim) nodes_status1.restrict(nodes.domain) else nodes_status1
+
+    if (nodes_status != nodes_status2) {
+      nodes_status = nodes_status2
       status.listData = nodes.topological_order.filter(nodes_status.defined(_))
     }
   }
@@ -253,7 +258,9 @@
         }
 
       case changed: Session.Commands_Changed =>
-        GUI_Thread.later { handle_update(Some(changed.nodes)) }
+        GUI_Thread.later {
+          handle_update(restriction = Some(changed.nodes), trim = changed.assignment)
+        }
     }
 
   override def init()