Skip to content

Commit

Permalink
[Mono.Cairo] Clean up Region's Dispose/ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutch committed Jun 19, 2013
1 parent 0bb971d commit 7085bed
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions mcs/class/Mono.Cairo/Mono.Cairo/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,20 @@ public IntPtr Handle {
get { return handle; }
}

~Region ()
{
Console.WriteLine ("Cairo.Region finalizer reached - developer must dispose regions manually to avoid leakage due to thread-safety concerns.");
}

[Obsolete]
public Region (IntPtr handle) : this (handle, false) {}

public Region (IntPtr handle, bool owned)
{
this.handle = handle;
if (!owned)
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)
Expand All @@ -81,14 +78,29 @@ public Region Copy ()
return new Region (NativeMethods.cairo_region_copy (Handle), true);
}

~Region ()
{
Dispose (false);
}

public void Dispose ()
{
if (handle != IntPtr.Zero)
NativeMethods.cairo_region_destroy (Handle);
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);
handle = IntPtr.Zero;
}

public override bool Equals (object obj)
{
return (obj is Region) && NativeMethods.cairo_region_equal (Handle, (obj as Region).Handle);
Expand Down

0 comments on commit 7085bed

Please sign in to comment.