Yes, that’s wrong. Start with sNetworkManagerboth niland consider two threads T1 and T2.
One possible, if unlikely, scenario:
T1: Determines (sNetworkManager == nil) is true
T2: Determines (sNetworkManager == nil) is true
T1: Takes the @synchronized lock
Creates a NetworkManager
Sets sNetworkManager
Releases the lock
T2: Takes the @synchronized lock
Creates a NetworkManager
Sets sNetworkManager, LEAKING the first one
Releases the lock
This question contains safer ways to do it.
source
share