Hello,

(Note: I haven't run your code, so my analysis is purely based on the
code reading.)

I think you should avoid releasing objects inside notification
callbacks, as you may release object that triggers the notification,
or object that handles the notification (that why a crash occurs). You
should find another design to to what you want.

Regards, Laurent Etiemble.

2009/6/23 Kenny Clement <psyki...@gmail.com>:
> Hi,
>
> I've been having some issues with memory management with a Monobjc project.
> I don't whether I'm doing something wrong here (most likely) , or if
> it's a Monobjc bug.
>
> In my project, and this sample application, I have a NIB with the File's
> owner set to my custom class.
> I have an NSWindow, which the File's owner as it's delegate.
> When the window closes, I Release() the custom class (File's owner).
>
> Problem #1) This all works fine. Until I want to use a NIB outlet in my
> code.
> As soon as I add an [NSObjectiveCField], it crashes when the class deallocs.
> Crash log can be found below.
>
> Problem #2) I needed some Cocoa binding. I bind to another custom class
> which just contains a property.
> The class is used (class set in the NIB file), but I can see that it never
> gets dealloc'd. Do I need
> to Release() it manually? (even though I never alloc'd myself?). I expect it
> to
> dealloc at least when the application exits.
>
> ===========
>
> I've written a small sample app to show the problems.
> In the attached sample, Monobjc 1.0 binaries have been used, because I
> need Tiger compatibility.
> Use the 'nant clean build' command to create an app in the dist folder.
>
> You'll see that the sample works perfectly, no crashes.
> If you check the logging however, you'll notice problem #2: Dealloc is
> never called on the viewmodel
>
> To see problem #1: in MainWindow.cs, uncomment line 12: //[ObjectiveCField].
> Rebuild.
> Open the app, close the window, or quit the App: Crash!
>
> Crashlog:
>
> Deallocating form: MainWindow
> Cleanup
> Stacktrace:
>
>   at (wrapper managed-to-native)
> Monobjc.SafeNativeMethods.object_setInstanceVariable
> (intptr,string,intptr)<0x00004>
>   at (wrapper managed-to-native)
> Monobjc.SafeNativeMethods.object_setInstanceVariable
> (intptr,string,intptr)<0xffffffff>
>   at Monobjc.Dynamic.Proxies.BindingExample.MainWindow.ExportMembers
> (BindingExample.MainWindow)<0x00033>
>   at
> Monobjc.Dynamic.Proxies.BindingExample.MainWindow.windowWillClose_Monobjc_Cocoa_NSNotification
> (intptr,intptr,intptr)<0x0005b>
>   at (wrapper native-to-managed)
> Monobjc.Dynamic.Proxies.BindingExample.MainWindow.windowWillClose_Monobjc_Cocoa_NSNotification
> (intptr,intptr,intptr)<0xffffffff>
>   at (wrapper managed-to-native) 4FBC41BB.pinvoke (intptr,intptr)<0x00004>
>   at (wrapper managed-to-native) 4FBC41BB.pinvoke (intptr,intptr)
> <0xffffffff>
>   at 4FBC41BB.objc_msgSend (intptr,intptr,object[])<0x00013>
>   at Monobjc.Bridge.Generators.DynamicMessagingGenerator.SendMessage
> (string,intptr,intptr,object[])<0x000ea>
>   at Monobjc.ObjectiveCRuntime.SendMessage
> (Monobjc.IManagedWrapper,string,object[])<0x00071>
>   at Monobjc.Cocoa.NSApplication.Run ()<0x0002a>
>   at Monobjc.Cocoa.NSApplication.RunApplication ()<0x0001c>
>   at BindingExample.Program.Main ()<0x00039>
> Abort trap
>
>
>
> I hope you can help,
>
> Thanks in advance!
>
>
> Kenny Clement
>
>
>

Reply via email to