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); + } + } } }