Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 2050 [details]
Sample MonoMac project to reproduce the issue. Simply run the sample. The main screen describes what to do.
I'm getting random crashes in my MonoMac application in the "NSObject.MonoMac_Disposer.Drain" method:
at (wrapper managed-to-native) MonoMac.ObjCRuntime.Messaging.void_objc_msgSendSuper (intptr,intptr) <IL 0x00024, 0xffffffff>
at MonoMac.Foundation.NSObject/MonoMac_Disposer.Drain (MonoMac.Foundation.NSObject) [0x0003b] in /Development/github/monomac/src/Foundation/NSObject.cs
at (wrapper dynamic-method) object.[MonoMac.Foundation.NSObject+MonoMac_Disposer.Void Drain(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x00011, 0x0004b>
at (wrapper native-to-managed) object.[MonoMac.Foundation.NSObject+MonoMac_Disposer.Void Drain(MonoMac.Foundation.NSObject)] (MonoMac.Foundation.NSObject,MonoMac.ObjCRuntime.Selector,MonoMac.Foundation.NSObject) <IL 0x000b6, 0xffffffff>
at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string) <IL 0x0009d, 0xffffffff>
By building my own version of MonoMac, I've been able to figure out that this crash always occurs when it's trying to dispose of the "super_handle" of my NSWindow subclass.
A sample is attached that does the following to reproduce the issue:
1) Create a new MonoMac document based project.
2) Create a subclass of NSWindow:
public class TestWindow : NSWindow
public TestWindow () : base(new RectangleF(100,100,500,500),NSWindowStyle.Resizable | NSWindowStyle.Closable, NSBackingStore.Buffered, false)
public TestWindow (IntPtr aIntPtr) : base(aIntPtr)
3) Use interface builder to have one of the pull down menus send the message "showTestWindow:".
4) Add the following to your AppDelegate class:
private TestWindow testWindow;
public void ShowTestWindow()
if (testWindow == null)
testWindow = new TestWindow();
testWindow.WillClose += HandleWillClose;
void HandleWillClose (object sender, EventArgs e)
testWindow.WillClose -= HandleWillClose;
testWindow = null;
5) Run the application, and open and close the window using the "wired up" menu item multiple times until it crashes. Should take less than 20 seconds to make it crash.
I found the cause of this, so I'm not sure if this is really a bug, or even if this is a case that MonoMac should handle.
I had forgotten that NSWindow has a property called "ReleasedWhenClosed", which is set to true by default. Once I set that to false, then everything works fine.
Ideally, it would be nice if the MonoMac disposer could detect that the native object has already been released to prevent the exception above to be called.
Haven't looked at this yet, but this may be related to the problem in bug #1086:
native code takes ownership of the object, but the managed garbage collector is not aware of that.
I downloaded the sample and tested it on the latest stable builds and was unable to reproduce the crash.