From 57b8aa15d298e167c535d72ca86f57545f6d0f55 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 15 Apr 2018 16:54:05 -0700 Subject: [PATCH] Call dispose at the end of the session --- Ooui/WebSocketSession.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Ooui/WebSocketSession.cs b/Ooui/WebSocketSession.cs index b18a82c..5c472df 100644 --- a/Ooui/WebSocketSession.cs +++ b/Ooui/WebSocketSession.cs @@ -23,10 +23,13 @@ namespace Ooui DateTime lastTransmitTime = DateTime.MinValue; readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps); + readonly bool disposeElementWhenDone; + public WebSocketSession (WebSocket webSocket, Element element, bool disposeElementWhenDone, double initialWidth, double initialHeight, CancellationToken serverToken) : base (element, initialWidth, initialHeight) { this.webSocket = webSocket; + this.disposeElementWhenDone = disposeElementWhenDone; // // Create a new session cancellation token that will trigger @@ -112,6 +115,15 @@ namespace Ooui } finally { element.MessageSent -= handleElementMessageSent; + + if (disposeElementWhenDone && (element is IDisposable disposable)) { + try { + disposable.Dispose (); + } + catch (Exception ex) { + Error ("Failed to dispose of element", ex); + } + } } }