[Mac] Explicitly retain/release CocoaWindowInfo instances

This commit is contained in:
thefiddler 2014-05-14 18:01:08 +02:00
parent 290cc91275
commit 1419c1e3a0
3 changed files with 10 additions and 2 deletions

View file

@ -38,6 +38,7 @@ namespace OpenTK.Platform.MacOS
public static readonly IntPtr Init = Selector.Get("init"); public static readonly IntPtr Init = Selector.Get("init");
public static readonly IntPtr InitWithCoder = Selector.Get("initWithCoder:"); public static readonly IntPtr InitWithCoder = Selector.Get("initWithCoder:");
public static readonly IntPtr Alloc = Selector.Get("alloc"); 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 Release = Selector.Get("release");
public static readonly IntPtr Autorelease = Selector.Get("autorelease"); public static readonly IntPtr Autorelease = Selector.Get("autorelease");

View file

@ -1021,7 +1021,7 @@ namespace OpenTK.Platform.MacOS
trackingArea = IntPtr.Zero; trackingArea = IntPtr.Zero;
} }
Cocoa.SendVoid(windowInfo.Handle, Selector.Release); windowInfo.Dispose();
} }
OnDisposed(EventArgs.Empty); OnDisposed(EventArgs.Empty);

View file

@ -68,6 +68,7 @@ namespace OpenTK.Platform.MacOS
{ {
this.nsWindowRef = nsWindowRef; this.nsWindowRef = nsWindowRef;
this.nsViewRef = nsViewRef; this.nsViewRef = nsViewRef;
Cocoa.SendVoid(nsWindowRef, Selector.Retain);
} }
#endregion #endregion
@ -107,16 +108,22 @@ namespace OpenTK.Platform.MacOS
if (disposing) if (disposing)
{ {
Cocoa.SendVoid(nsWindowRef, Selector.Release);
}
else
{
Debug.Print("CocoaWindowInfo:{0} leaked, did you forget to call Dispose()?", nsWindowRef);
} }
disposed = true; disposed = true;
} }
#if DEBUG
~CocoaWindowInfo() ~CocoaWindowInfo()
{ {
Dispose(false); Dispose(false);
} }
#endif
#endregion #endregion
} }