2

I got some questions after reading the answer to this thread Handling Pointer-to-Pointer Ownership Issues in ARC;

For demo 1, when a reference to a 'strong' attributed variable is passed, a hidden(__autoreleasing) variable is implicitly created and the object doesn't get retained. However for demo 4, when a reference to a 'weak' attributed variable is passed, the object does get retained once.

So my question is quite simple as just my curiosity, why only the hidden variable created from '__weak' gets the object retain+1? Is this pattern designed for any special concerns?

Hoping I explain my question clearly, any help will be appreciated.

Community
  • 1
  • 1
Dirk Zhou
  • 51
  • 3
  • 1
    This looks like an interesting question, but you should copy the relevant code and paste it directly into your text so people can understand without jumping between pages. – nevan king Mar 27 '13 at 15:49
  • I believe weak references are retained/autoreleased when they are accessed--this prevents them from zeroing part way through a method using a weak reference. – nielsbot Mar 27 '13 at 15:54
  • @nevan king: i tried to copy and paste here, but the demo snippets there are long and messed up as well as with many comments. thanks for your reply anyway. – Dirk Zhou Mar 28 '13 at 01:54

1 Answers1

0

a hidden(__autoreleasing) variable is implicitly created and the object doesn't get retained

This is not true. __autoreleasing is something that is retained and autoreleased.

newacct
  • 119,665
  • 29
  • 163
  • 224