0

Today I read book about ARC. So there are two type points both strong and weak points. I already searched the property about them and got it. But I couldn't see or understand why we use weak point instead of strong? This is simple question. Please let me know easily.

Thanks.

Duckchan
  • 11
  • 1
  • http://stackoverflow.com/questions/8927727/objective-c-arc-strong-vs-retain-and-weak-vs-assign – Coldsteel48 Mar 21 '14 at 04:08
  • @Roma-MT Thanks for your reply. I will read the link. – Duckchan Mar 26 '14 at 21:32
  • @Roma-MT [Transitioning to ARC Release Notes](https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html) link is good for me. Thanks. – Duckchan Mar 26 '14 at 21:41
  • I am alwas glad to help bro !! -cheers 1 more for me !! and for you luck HEEEY !!!! :))) damn st. patrick day is over .. but i am stillin the mood ))) – Coldsteel48 Mar 26 '14 at 22:36
  • Well if you dont mind I will make an answer based on this comment (in hope it helped you. – Coldsteel48 Mar 26 '14 at 22:47

3 Answers3

1

First of all its not weak points, its weak property. Lets say if you don't want owner ship of a particular object you can use weak property. If the actual owner of this reference release this and its retain count becomes zero, a weak reference will be automatically assigned to nil. Which will save you from crashes.

You can get more information here : https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html

Naga Mallesh Maddali
  • 1,005
  • 10
  • 19
0

This question has been answered very well on apple's page ! I will just link it in hope it really helped you to get the required info !

link is here :) arc

also I think this SO question is very helpful for understanding the things :[link]here (Objective-C ARC: strong vs retain and weak vs assign)

Community
  • 1
  • 1
Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
0

To be simple, you use "weak property" and or "weak variable" for following:

  1. You do not want to take the ownership of object. Like delegate/dataSource are generally declared weak.
  2. You may say you can also use "assign" instead of "weak". When the variable is freed from memory, using "weak" automatically sets it to nil, whereas "assign" now is referring to deallocated instance and code can crash if you try to do something on it.
  3. To avoid retain cycles causing memory leaks. For example avoid passing "self" in blocks. use "__weak id weakSelf = self", and now pass weakSelf in blocks.

ARC is your friend, but can do potential harm if not taken care of things mentioned above.

gagarwal
  • 4,224
  • 2
  • 20
  • 27