Thread safe lazy initialization on iOS
I have a view controller that I want to lazily initialize, and once initialized, use the same copy when possible (I don't use a singleton since I do want to remove it from memory eventually), I use the getter to do so, my code look like this: @property (retain) UIViewController *myController ... @synthesize myController = _myController; ... - (UIViewController *)myController { if (!_myController) { // Evaluation _myController = [[MyViewController alloc] init]; // Object Creation } return _myController; } This works, but it's not thread safe, and if more than one thread evaluate to true before