B
B
Bullstreak2014-08-23 19:57:34
Objective-C
Bullstreak, 2014-08-23 19:57:34

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

2 answer(s)
D
Denis Morozov, 2014-08-23
@morozovdenis

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

V
Vanya Ivanov, 2015-01-04
@mr_cloud

https://vk.com/videos-58860049?z=video-58860049_16...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question