cairo: Clean up Region's Dispose/ctor
This commit is contained in:
parent
50ee23f0f2
commit
bdc2cfdf1d
1 changed files with 22 additions and 10 deletions
|
@ -47,11 +47,7 @@ namespace Cairo
|
||||||
get { return handle; }
|
get { return handle; }
|
||||||
}
|
}
|
||||||
|
|
||||||
~Region ()
|
[Obsolete]
|
||||||
{
|
|
||||||
Console.WriteLine ("Cairo.Region finalizer reached - developer must dispose regions manually to avoid leakage due to thread-safety concerns.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region (IntPtr handle) : this (handle, false) {}
|
public Region (IntPtr handle) : this (handle, false) {}
|
||||||
|
|
||||||
public Region (IntPtr handle, bool owned)
|
public Region (IntPtr handle, bool owned)
|
||||||
|
@ -59,11 +55,12 @@ namespace Cairo
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
if (!owned)
|
if (!owned)
|
||||||
NativeMethods.cairo_region_reference (handle);
|
NativeMethods.cairo_region_reference (handle);
|
||||||
|
if (CairoDebug.Enabled)
|
||||||
|
CairoDebug.OnAllocated (handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region ()
|
public Region () : this (NativeMethods.cairo_region_create () , true)
|
||||||
{
|
{
|
||||||
handle = NativeMethods.cairo_region_create ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Region (RectangleInt rect)
|
public Region (RectangleInt rect)
|
||||||
|
@ -81,12 +78,27 @@ namespace Cairo
|
||||||
return new Region (NativeMethods.cairo_region_copy (Handle), true);
|
return new Region (NativeMethods.cairo_region_copy (Handle), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Region ()
|
||||||
|
{
|
||||||
|
Dispose (false);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose ()
|
public void Dispose ()
|
||||||
{
|
{
|
||||||
if (handle != IntPtr.Zero)
|
Dispose (true);
|
||||||
|
GC.SuppressFinalize (this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposing || CairoDebug.Enabled)
|
||||||
|
CairoDebug.OnDisposed<Region> (handle, disposing);
|
||||||
|
|
||||||
|
if (!disposing|| handle == IntPtr.Zero)
|
||||||
|
return;
|
||||||
|
|
||||||
NativeMethods.cairo_region_destroy (Handle);
|
NativeMethods.cairo_region_destroy (Handle);
|
||||||
handle = IntPtr.Zero;
|
handle = IntPtr.Zero;
|
||||||
GC.SuppressFinalize (this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals (object obj)
|
public override bool Equals (object obj)
|
||||||
|
|
Loading…
Reference in a new issue