Answer the question
In order to leave comments, you need to log in
What is the difference between weak and strong?
I watched courses from Stanford, I realized that these are attributes of pointers. But I don't understand the difference.
Answer the question
In order to leave comments, you need to log in
strong - a strong reference, and when assigned to a property with strong, the number of object references increases
weak - a weak reference, and when assigned to a property with weak, the number of object references does NOT increase, and when the object is deleted, this property is assigned nil
example:
@property (strong, nonatomic) NSObject *a;
@property (weak, nonatomic) NSObject *b;
NSObject *_a = [NSObject new]; // retainCount == 1
self.a = _a; //retainCount == 2
_a = nil; // объект ещё не удалён , retainCount == 1
self.a = nil; // объект будет удален
NSObject *_b = [NSObject new]; // retainCount == 1
self.b = _b; // retainCount == 1
_b = nil; // объект будет удален, а в self.b будет nil
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question