11

Possible Duplicate:
Objective-C properties: atomic vs nonatomic

By default all properties in Objective-C are atomic. If I need nonatomic I have to declare it. But I wonder why should I ever use nonatomic? Even if my applications are not multi threaded, atomic seems like the way to do it. What are the advantages of nonatomic?

Community
  • 1
  • 1
TalkingCode
  • 12,759
  • 27
  • 96
  • 141
  • 5
    @KennyTM: This is not a duplicate of your linked question. That was asking what atomic/nonatomic means which is not the same as asking if you should ever use nonatomic. – JeremyP Oct 31 '10 at 23:11

1 Answers1

18

A short answer is performance. If you declare properties as atomic, the synthesized accessors will use locks to ensure that values are fully retrieved and set. If you don't need this, e.g., your application is single-threaded, you're incurring a performance penalty for those locks without getting a benefit.

James Huddleston
  • 8,222
  • 4
  • 32
  • 39
  • 6
    And therefore setting properties to nonatomic without profiling counts as premature optimisation. – JeremyP Oct 31 '10 at 23:12
  • 1
    I am also intrested if this can really be significant for performance in common application to use this property, without nonatomic it is just more readable , one unused keyword free... – Renetik Oct 25 '12 at 08:46