I\'m new to Obj-C, so my first question is:
What are the differences between strong
and weak
in @property
declarations of poin
strong is the default. An object remains “alive” as long as there is a strong pointer to it.
weak specifies a reference that does not keep the referenced object alive. A weak reference is set to nil when there are no strong references to the object.
A dummy answer :-
I think explanation is given in above answer, so i am just gonna tell you where to use STRONG
and where to use WEAK
:
Use of Weak
:-
1. Delegates
2. Outlets
3. Subviews
4. Controls, etc.
Use of Strong
:-
Remaining everywhere which is not included in WEAK
.
strong: assigns the incoming value to it, it will retain the incoming value and release the existing value of the instance variable
weak: will assign the incoming value to it without retaining it.
So the basic difference is the retaining of the new variable. Generaly you want to retain it but there are situations where you don't want to have it otherwise you will get a retain cycle and can not free the memory the objects. Eg. obj1 retains obj2 and obj2 retains obj1. To solve this kind of situation you use weak references.