I have noticed my application freezing up at random times after some recent updates. In this past, random freezing has been my fault (accessing NSApplication from a non-UI thread). But Xamarin did add a bunch of checks to some NS* classes which caught instances of that problem.

It's also happened when some object has gone out of scope but the native runtime has a handle to it.

To avoid, I have this before NSApplication.Init and NSApplication.Main:

Which should aggressively crash the application if I "lose" an object that the native runtime relies on (i.e. make sure the GC runs, because if it doesn't the object I've "lost" won't be collected and the app might still run okay). But from time to time the application crashes and the stack trace looks like:

Your sample works just fine, and funnily enough my sample in the crashing app works fine at the mo too!

However, I've just done some further digging in the code and I've noticed some InvokeOnMainThread calls that are unnecessary as it's already running on the main thread. If I toggle using the invoke and not using it. I can't get it to crash when it isn't used but it crashes very regularly when it is used. It seems that this is the culprit.

Is there no way of selectively invoking on the main thread like in .net "InvokeRequired" ??

I'm moving into theory territory here but this very same code which is now crashing in Mavericks has been around for a while and wasn't crashing before Mavericks. So, it's certainly possible that Mavericks is more sensitive to receiving unnecessary InvokeOnMainThread calls when the code is already on the main thread.

So I'm guessing that if InvokeOnMainThread can be called conditionally only when needed we may have a resolution here!

Hi Vivek, I'm afraid I can't help, the issue mysteriously went away with a Xamarin.Mac update and no code changes on our side but I can't get any information out of Xamarin as to what is likely to have fixed it.

There seems to be all sorts of problems with Xamarin.Mac since Mavericks but I'm having a really hard time getting to the bottom of it to work out whether it's code or Xamarin library related.

I'm trying to work with Xamarin support on it but it's difficult because I'm not getting much response from them at the moment. Whether that means they are aware of issues and are beavering about in the background trying to sort it or they are not giving it much attention I have no idea

We are actively investigating the issue. We've found the issue is propagating in native code which has added to the difficulty in locating the cause of the issue but I am currently in the room with 3 of our Mac engineers all working on finding a solution for you.

Once they have located the cause of the problem then they can set about finding a solution for you and we will be in touch.