~FontFace ()
{
- // Since Cairo is not thread safe, we can not unref the
- // font_face here, the programmer must do this with Dispose
-
- Console.Error.WriteLine ("Programmer forgot to call Dispose on the FontFace");
Dispose (false);
}
public void Dispose ()
{
Dispose (true);
+ GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
- if (disposing)
- NativeMethods.cairo_font_face_destroy (handle);
+ if (handle == IntPtr.Zero)
+ return;
+
+ if (!disposing) {
+ Console.Error.WriteLine ("Cairo.FontFace: called from finalization thread, programmer is missing a call to Dispose");
+ return;
+ }
+
+ NativeMethods.cairo_font_face_destroy (handle);
handle = IntPtr.Zero;
- GC.SuppressFinalize (this);
}
// TODO: make non-public when all entry points are complete in binding
public class FontOptions : IDisposable
{
IntPtr handle;
- bool disposed;
public FontOptions ()
{
return new FontOptions (NativeMethods.cairo_font_options_copy (handle));
}
+ [Obsolete ("Use Dispose()")]
public void Destroy ()
{
- NativeMethods.cairo_font_options_destroy (handle);
+ Dispose ();
}
public void Dispose ()
GC.SuppressFinalize (this);
}
- private void Dispose (bool disposing)
+ protected virtual void Dispose (bool disposing)
{
- if (!disposed) {
- Destroy ();
- handle = IntPtr.Zero;
+ if (handle == IntPtr.Zero)
+ return;
+
+ if (!disposing) {
+ Console.Error.WriteLine ("Cairo.FontOptions: called from finalization thread, programmer is missing a call to Dispose");
+ return;
}
- disposed = true;
+
+ NativeMethods.cairo_font_options_destroy (handle);
+ handle = IntPtr.Zero;
}
public static bool operator == (FontOptions options, FontOptions other)
public class Path : IDisposable
{
- internal IntPtr handle = IntPtr.Zero;
+ internal IntPtr handle = IntPtr.Zero;
internal Path (IntPtr handle)
{
protected virtual void Dispose (bool disposing)
{
- if (!disposing){
- Console.Error.WriteLine ("Cairo.Context: called from finalization thread, programmer is missing a call to Dispose");
+ if (!disposing) {
+ Console.Error.WriteLine ("Cairo.Path: called from finalization thread, programmer is missing a call to Dispose");
return;
}
public class Pattern : IDisposable
{
- protected IntPtr pattern = IntPtr.Zero;
+ protected IntPtr pattern = IntPtr.Zero;
internal static Pattern Lookup (IntPtr pattern)
{
~Pattern ()
{
+ Dispose (false);
}
[Obsolete ("Use the SurfacePattern constructor")]
public void Dispose ()
{
Dispose (true);
+ GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
- if (disposing)
- Destroy ();
- GC.SuppressFinalize (this);
- }
-
- public void Destroy ()
- {
- if (pattern != IntPtr.Zero){
- NativeMethods.cairo_pattern_destroy (pattern);
- pattern = IntPtr.Zero;
+ if (!disposing) {
+ Console.Error.WriteLine ("Cairo.Pattern: called from finalization thread, programmer is missing a call to Dispose");
+ return;
}
+
+ if (pattern == IntPtr.Zero)
+ return;
+
+ NativeMethods.cairo_pattern_destroy (pattern);
+ pattern = IntPtr.Zero;
lock (patterns){
patterns.Remove (this);
}
+ }
+
+ [Obsolete ("Use Dispose()")]
+ public void Destroy ()
+ {
+ Dispose ();
}
public Status Status
protected virtual void Dispose (bool disposing)
{
- if (disposing) {
- NativeMethods.cairo_scaled_font_destroy (handle);
- handle = IntPtr.Zero;
+ if (handle == IntPtr.Zero)
+ return;
+
+ if (!disposing) {
+ Console.Error.WriteLine ("Cairo.ScaledFont: called from finalization thread, programmer is missing a call to Dispose");
+ return;
}
+
+ NativeMethods.cairo_scaled_font_destroy (handle);
+ handle = IntPtr.Zero;
}
protected void Reference ()
{
if (surface == IntPtr.Zero)
return;
+ if (!disposing) {
+ Console.Error.WriteLine ("Cairo.Surface: called from finalization thread, programmer is missing a call to Dispose");
+ return;
+ }
lock (surfaces.SyncRoot)
surfaces.Remove (surface);