0

I have a Cocoa class bound in monomac. If I call Dispose() on an instance of that class, should it always invoke dealloc on the unmanaged side?

What reasons might there be for dealloc not being invoked when the managed class is Dispose()ed?

TheNextman
  • 12,428
  • 2
  • 36
  • 75

1 Answers1

3

Dispose on the managed object will call release on the native object, not dealloc (but it may end up deallocating the object if nobody else has retained it).

Note that calling Dispose multiple times will only call release once.

Update

This turned out to be a bug in MonoMac / Xamarin.Mac (which has now been fixed).

Rolf Bjarne Kvinge
  • 19,253
  • 2
  • 42
  • 86
  • What causes an object to be sent `retain` in managed code? Simply taking a reference to it? – TheNextman Oct 11 '13 at 22:22
  • 1
    Whenever a managed wrapper is created for an Objective-C object, `retain` will be called. Then `release` will be called when the managed object is destroyed (or you call `Dispose` manually). – Rolf Bjarne Kvinge Oct 14 '13 at 07:40
  • I have raised bug 15405 in relation to this behaviour... Rolf, any chance you can take a look and let me know if I'm doing something wrong? https://bugzilla.xamarin.com/show_bug.cgi?id=15405 – TheNextman Oct 15 '13 at 14:32