title: If you have an IBOutlet, but not a property, is it retained or not?
body: <p>I find the documentation on this issue to be unclear:</p>
  <p>Say you are working with iOS (NOT the Mac case, no need to mention the differences). Say it is strictly 4.0+ (no need to mention differences in old OS). Say we are loading the NIB strictly automatically.</p>
  <p>Say you have a UIViewController, BigView. Say there are a dozen so-called &quot;top-level&quot; items in the NIB file...could be custom controls, images, or anything else.</p>
  <p>Say you are definitely going to explicitly create and then get rid of BigView a number of times during the app's run.  So:</p>
  <p>For one of these top-level items in the NIB, there are <strong>three possibilities</strong>:</p>
  <p>(1) You do not have any sort of IBOutlet for it, at all.</p>
  <p>(2) You do have a connected IBOutlet - but not a property.</p>
  <p>(3) You do have a connected IBOutlet property (to avoid confusion, we'll say a retain property).</p>
  <p>So what happens to the item when BigView is released?</p>
  <p><strong>In the case of (3)</strong> it seems clear that you must release explicitly.  If you do not, it will hang around after the view is gone.  No problem.</p>
  <p><strong>In the case of (1)</strong> I assume (<strong>but can anyone actually confirm?</strong>) that the item will be released when BigView is gone.</p>
  <p><strong>In the case of (2)</strong> it's not clear what happens.......</p>
  <p>Looking at the well-known reference link: <a href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html" rel="nofollow noreferrer">https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html</a> it is very dubious:</p>
  <blockquote>
  <p>&quot;In iOS, the nib-loading code uses the setValue:forKey: method to reconnect each outlet. That method similarly looks for an appropriate accessor method and [SO WHAT HAPPENS IF THERE ISN'T ONE?? TELL US APPLE...] falls back on other means when that fails...[GOOD GRIEF!]&quot;</p>
  </blockquote>
  <p>And scroll down to &quot;Nib Object Retention&quot;:</p>
  <blockquote>
  <p><strong>&quot;Objects in the nib file are created with a retain count of 1 and then autoreleased&quot;</strong> Fantastic..</p>
  </blockquote>
  <p>But wait!  Read on a few words...</p>
  <blockquote>
  <p><strong>however, ... which uses the available setter method or retains the object by default if no setter method is available</strong></p>
  </blockquote>
  <p>What are they talking about?</p>
  <p>Do they mean that if no setter is available (ivar, but no property), that it is <strong>AGAIN</strong> RETAINED (other than the &quot;retain&quot; they just mention in the previous clause) --- or, are they just repeating themselves, i.e. the &quot;retains the object by default&quot; is the same &quot;retain&quot; they were talking about immediately previously (&quot;created with a retain count of 1 and then autoreleased&quot;).</p>
  <p>And why would they even mention the autorelease if that's not what happens?</p>
  <p>Indeed -- if anyone actually specifically knows the answer to this question ...... <strong>how do you know?!?</strong> Did you ask DTS, or through testing, or?  I suggest, the key documentation (just pasted in) is aggressively unclear.</p>
  <p>Again - if you have an IBOutlet, <strong>but not a property</strong>, connected to a &quot;top-level&quot; object .. <strong>are you responsible for releasing it? Is it retained?</strong> in that situation?</p>
  <p>For that matter .... merely in situation (1) is it absolutely the case that the thingy will be released when BigView goes away?  I would certainly assume this is the case, but who knows?</p>
  <p>The question is what happens if you DO use an IBOutlet iVar, but NOT a property...</p>
  <p>I've foolishly never thought about this before / assumed too much, does anyone have the decisive answer?  Cheers!!</p>
  <hr />
  <p>For the record I have made a test project.</p>
  <p>In fact (surprisingly to me) <strong>the mere act of connecting an IB element to an IBOutlet in fact apparently adds one retain</strong>.</p>
  <p>(I can only assume from the shoddy docu, in that situation you get specifically: Retain, Autorelease, Retain - leading to one retain on balance.)</p>
  <p>So, that's the answer.</p>
  <p>I will post the demo project. I also direct any readers to Jonah's answer below which flawlessly explains the behavior of setValue:forKey:   Cheers</p>