From f5211acb746789b9d282e906b33720b4e7f61a3a Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 5 Jul 2014 15:44:21 +0200 Subject: [PATCH] glib: Have SourceProxy implement the Dispose pattern Its 2 subclasses, IdleProxy and TimeoutProxy, were already implementing it, so we factor this implementation into the base class. --- glib/Idle.cs | 24 ------------------------ glib/Source.cs | 26 +++++++++++++++++++++++++- glib/Timeout.cs | 24 ------------------------ 3 files changed, 25 insertions(+), 49 deletions(-) diff --git a/glib/Idle.cs b/glib/Idle.cs index 407969411..189b3a8b0 100644 --- a/glib/Idle.cs +++ b/glib/Idle.cs @@ -44,30 +44,6 @@ namespace GLib { proxy_handler = new IdleHandlerInternal (Handler); } - ~IdleProxy () - { - Dispose (false); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - // Both branches remove our delegate from the - // managed list of handlers, but only - // Source.Remove will remove it from the - // unmanaged list also. - - if (disposing) - Remove (); - else - Source.Remove (ID); - } - public bool Handler () { try { diff --git a/glib/Source.cs b/glib/Source.cs index 0140d7402..2ab98e572 100644 --- a/glib/Source.cs +++ b/glib/Source.cs @@ -31,11 +31,35 @@ namespace GLib { // // Base class for IdleProxy and TimeoutProxy // - internal class SourceProxy { + internal class SourceProxy : IDisposable { internal Delegate real_handler; internal Delegate proxy_handler; internal uint ID; + ~SourceProxy () + { + Dispose (false); + } + + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + // Both branches remove our delegate from the + // managed list of handlers, but only + // Source.Remove will remove it from the + // unmanaged list also. + + if (disposing) + Remove (); + else + Source.Remove (ID); + } + internal void Remove () { Source.RemoveSourceHandler (ID); diff --git a/glib/Timeout.cs b/glib/Timeout.cs index ceaf98e3a..2e68e068f 100644 --- a/glib/Timeout.cs +++ b/glib/Timeout.cs @@ -42,30 +42,6 @@ namespace GLib { proxy_handler = new TimeoutHandlerInternal (Handler); } - ~TimeoutProxy () - { - Dispose (false); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - // Both branches remove our delegate from the - // managed list of handlers, but only - // Source.Remove will remove it from the - // unmanaged list also. - - if (disposing) - Remove (); - else - Source.Remove (ID); - } - public bool Handler () { try {