I have a auto-synthesized readonly
& weak
property:
@property (nonatomic, readonly, weak) KTWindowController* windowController;
I assign the synthesized ivar and then add it to an array:
_windowController = [KTWindowController controller];
[self addSubController:_windowController];
This works fine in Debug builds. But I got a report that in release (ad hoc) builds this will immediately nil the _windowController
and then it tries to add nil to the array, crashing the app.
What specific setting (optimization level?) in a release (ad hoc) build changes this behavior compared to Debug builds?
It strikes me as odd that this behavior would change from Debug to Release builds. But I was able to reproduce this behavior, and it actually makes sense - just not when it's not coherent with what happens in debug builds.
The suggested workaround:
KTWindowController* windowController = [KTWindowController controller];
[self addSubController:windowController];
_windowController = windowController;
Other than using a local variable as seen above, what workaround would you recommend in cases like these?