From 75772261278adec91c40d76873a0f7eb48c3d29f Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sat, 14 Apr 2012 11:24:14 +0100 Subject: [PATCH] StatusIcon: dispose properly Override Dispose method of Component class, so it calls the backend's Dispose method. --- Xwt.Mac/Xwt.Mac/StatusIconBackend.cs | 6 ++++++ Xwt/Xwt.Backends/IStatusIconBackend.cs | 2 +- Xwt/Xwt/StatusIcon.cs | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Xwt.Mac/Xwt.Mac/StatusIconBackend.cs b/Xwt.Mac/Xwt.Mac/StatusIconBackend.cs index 713dae08..27a1ae26 100644 --- a/Xwt.Mac/Xwt.Mac/StatusIconBackend.cs +++ b/Xwt.Mac/Xwt.Mac/StatusIconBackend.cs @@ -62,6 +62,12 @@ namespace Xwt.Mac public void EnableEvent (object eventId) { throw new NotImplementedException (); } public void DisableEvent (object eventId) { throw new NotImplementedException (); } + + public void Dispose () + { + statusItem.Dispose (); + statusItem = null; + } } } diff --git a/Xwt/Xwt.Backends/IStatusIconBackend.cs b/Xwt/Xwt.Backends/IStatusIconBackend.cs index c6a03452..50f068fb 100644 --- a/Xwt/Xwt.Backends/IStatusIconBackend.cs +++ b/Xwt/Xwt.Backends/IStatusIconBackend.cs @@ -29,7 +29,7 @@ using System.Collections.ObjectModel; namespace Xwt.Backends { - public interface IStatusIconBackend : IBackend + public interface IStatusIconBackend : IBackend, IDisposable { void SetMenu (object menuBackend); diff --git a/Xwt/Xwt/StatusIcon.cs b/Xwt/Xwt/StatusIcon.cs index b43c06ff..b8cf8893 100644 --- a/Xwt/Xwt/StatusIcon.cs +++ b/Xwt/Xwt/StatusIcon.cs @@ -54,6 +54,16 @@ namespace Xwt IStatusIconBackend Backend { get { return (IStatusIconBackend) BackendHost.Backend; } } + + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + + // Don't dispose the backend if this object is being finalized + // The backend has to handle the finalizing on its own + if (disposing && BackendHost.BackendCreated) + Backend.Dispose (); + } } }