diff options
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/FontFace.cs | 9 | ||||
-rw-r--r-- | mcs/class/Mono.Cairo/Mono.Cairo/Pattern.cs | 22 |
2 files changed, 24 insertions, 7 deletions
diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/FontFace.cs b/mcs/class/Mono.Cairo/Mono.Cairo/FontFace.cs index 684bf0f80e7..a7adbd9339a 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo/FontFace.cs +++ b/mcs/class/Mono.Cairo/Mono.Cairo/FontFace.cs @@ -54,11 +54,18 @@ namespace Cairo // font_face here, the programmer must do this with IDisposable.Dispose Console.Error.WriteLine ("Programmer forgot to call Dispose on the FontFace"); + Dispose (false); } void IDisposable.Dispose () { - NativeMethods.cairo_font_face_destroy (handle); + Dispose (true); + } + + protected virtual void Dispose (bool disposing) + { + if (disposing) + NativeMethods.cairo_font_face_destroy (handle); handle = IntPtr.Zero; GC.SuppressFinalize (this); } diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/Pattern.cs b/mcs/class/Mono.Cairo/Mono.Cairo/Pattern.cs index a4ee9daa533..80a180ee332 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo/Pattern.cs +++ b/mcs/class/Mono.Cairo/Mono.Cairo/Pattern.cs @@ -76,9 +76,6 @@ namespace Cairo { ~Pattern () { - lock (patterns){ - patterns.Remove (this); - } } [Obsolete ("Use the SurfacePattern constructor")] @@ -92,14 +89,27 @@ namespace Cairo { NativeMethods.cairo_pattern_reference (pattern); } - public void Dispose () + void IDisposable.Dispose () + { + Dispose (true); + } + + protected virtual void Dispose (bool disposing) { - Destroy (); + if (disposing) + Destroy (); + GC.SuppressFinalize (this); } public void Destroy () { - NativeMethods.cairo_pattern_destroy (pattern); + if (pattern != IntPtr.Zero){ + NativeMethods.cairo_pattern_destroy (pattern); + pattern = IntPtr.Zero; + } + lock (patterns){ + patterns.Remove (this); + } } public Status Status |