Objective-C Language Memory Management Strong and weak references


Example

Modern

A weak reference looks like one of these:

@property (weak) NSString *property;
NSString *__weak variable;

If you have a weak reference to an object, then under the hood:

  • You're not retaining it.
  • When it gets deallocated, every reference to it will automatically be set to nil

Object references are always strong by default. But you can explicitly specify that they're strong:

@property (strong) NSString *property;
NSString *__strong variable;

A strong reference means that while that reference exists, you are retaining the object.