Skip to content

Commit

Permalink
[Mac] Explicitly retain/release CocoaWindowInfo instances
Browse files Browse the repository at this point in the history
  • Loading branch information
thefiddler committed May 14, 2014
1 parent 290cc91 commit 1419c1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Source/OpenTK/Platform/MacOS/Cocoa/Selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static class Selector
public static readonly IntPtr Init = Selector.Get("init");
public static readonly IntPtr InitWithCoder = Selector.Get("initWithCoder:");
public static readonly IntPtr Alloc = Selector.Get("alloc");
public static readonly IntPtr Retain = Selector.Get("retain");
public static readonly IntPtr Release = Selector.Get("release");
public static readonly IntPtr Autorelease = Selector.Get("autorelease");

Expand Down
2 changes: 1 addition & 1 deletion Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ protected override void Dispose(bool disposing)
trackingArea = IntPtr.Zero;
}

Cocoa.SendVoid(windowInfo.Handle, Selector.Release);
windowInfo.Dispose();
}

OnDisposed(EventArgs.Empty);
Expand Down
9 changes: 8 additions & 1 deletion Source/OpenTK/Platform/MacOS/CocoaWindowInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public CocoaWindowInfo(IntPtr nsWindowRef, IntPtr nsViewRef)
{
this.nsWindowRef = nsWindowRef;
this.nsViewRef = nsViewRef;
Cocoa.SendVoid(nsWindowRef, Selector.Retain);
}

#endregion
Expand Down Expand Up @@ -107,16 +108,22 @@ void Dispose(bool disposing)

if (disposing)
{

Cocoa.SendVoid(nsWindowRef, Selector.Release);
}
else
{
Debug.Print("CocoaWindowInfo:{0} leaked, did you forget to call Dispose()?", nsWindowRef);
}

disposed = true;
}

#if DEBUG
~CocoaWindowInfo()
{
Dispose(false);
}
#endif

#endregion
}
Expand Down

0 comments on commit 1419c1e

Please sign in to comment.