> Le 4 sept. 2019 à 00:18, Turtle Creek Software <supp...@turtlesoft.com> a > écrit : > > The app delegate is NOT being deallocated prematurely- we have a breakpoint > there to check. > > We don't allocate the app delegate explicitly, so I had to set a breakpoint > in init() to see when it happens. > It's created in main() via NSApplicationMain. Presumably its end of scope > would be when main ends. > The MainMenu.xib includes a Delegate object for our GSAppDelegate class, so > it must be allocated > via the nib-loading process (the stack trace says InitWithCoder). > > GSAppDelegate has strong references to 4 window controller members: main > window, prefs window, and a couple of log windows. > But that alone has not kept the main window controller alive. We haven't > tested the others. > > The main window controller that was mysteriously dying used to have a strong > reference back to the app delegate. > Whether strong, weak or non-existent, it didn't make any difference. I > suppose we could add a strong ref somewhere else > just to be double safe, but I'm not sure where else would make sense.
You can get the same effect by retaining the controller explicitly (creating a leak, so should be for testing purpose only). CFBridgingRetain(windowController); > The startup code was created 3 years ago when we were new to Cocoa, probably > from one of the HIllegass books. > It may have flaws, but the app has been running OK otherwise. The problems > only started when we read about circular references > and started making up-references __weak. > > BTW the Clang specs for ARC mention that it's not exception-safe. If I > understand correctly, > strong references will leak, and weak references are released. We don't > throw any Cocoa exceptions but > maybe the system does. Manual Ref counting was not safe either, just like almost everything in Obj-C frameworks. Exception are used only for fatal errors (expect in a couple of legacy API). Don’t bother with exception safety. If your code raises an exception, fix the bug to avoid seeing it again. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com