Will using strong reference for IBOutlet cause memory leak? Apple recommends using weak for IBOutlet except for the file owner, but what happen if you use strong for all IBOutlet?
-
Already has very good answer here - http://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc – andykkt May 01 '14 at 00:06
-
Hi, the link doesn't answer my question - I saw it before asking this. I would like to know if using strong can cause issue, not whether I should use strong or weak (which is the recommendation) – Boon May 01 '14 at 00:21
-
Ok, I thought it would answer about the memory leak too because it explains about why IBOutlet is a weak pointer. Anyway, direct answer is "No, it will not cause memory leak" but it will make more memory hanging around in some very rare cases. – andykkt May 01 '14 at 03:07
1 Answers
If you are using ARC, it is almost impossible to cause a memory leak. That's part of the point of ARC! To cause a memory leak under ARC, you'd have to do something extraordinary, like a strong property referring to something that has a strong property referring back to you (retain cycle).
That can happen, but is improbable in this situation; nothing that you have an IBOutlet to is likely to retain you. You can certainly form a retain cycle between, say, a view controller and view instantiated from a nib that this view controller loads; but don't. Even ARC can't stop you from deliberately shooting yourself in the foot.
So, yes, using strong for an IBOutlet can cause an issue, but only for the same reason that using strong can always cause an issue: if you misuse it, you can cause a retain cycle. So don't misuse it!

- 515,959
- 87
- 875
- 1,141