Note that there are some explanatory texts on larger screens.

plurals
  1. POUnused IBOutlets leaking
    primarykey
    data
    text
    <p>So, I'm loading by XIB file and it contains a set of <code>UIBarButtonItems</code>. Some of the items are used when the <code>viewDidLoad:</code> is called.</p> <pre><code>@interface MyViewController : UIViewController { IBOutlet UIBarButtonItem *addButton; IBOutlet UIBarButtonItem *editButton; IBOutlet UIBarButtonItem *doneButton; } // NB: There are no properties retaining anything. @end @implementation MyViewController - (void)viewDidLoad { [super viewDidLoad]; NSArray *initialToolbarItems = [[NSArray alloc] initWithObjects: addButton, editButton, nil]; self.toolbarItems = initialToolbarItems; [initialToolbarItems release]; } - (void)dealloc { [super dealloc]; // Nothing else to do here since we are not retaining anything. // … or are we? &lt;insert dramatic music here&gt; } @end </code></pre> <p>If I push the above the above ViewController onto a UINavigationController everything seems fine, all the IBOutlets are assigned and behave like expected.</p> <p>The instant i pop the ViewController from the navigation stack <em>Instruments' Leaks</em> tells me that I am leaking a <code>UIBarButtonItem</code>. Woe is me!</p> <p>If I change <code>dealloc:</code> to</p> <pre><code>- (void)dealloc { [doneButton release]; [super dealloc]; } </code></pre> <p>no leaks occur. The same goes if I use <code>doneButton</code> in <code>viewDidLoad:</code></p> <pre><code> NSArray *initialToolbarItems = [[NSArray alloc] initWithObjects: addButton, editButton, doneButton, nil]; </code></pre> <p>My question: Why is my <code>IBOutlet</code> leaking when I don't use it. I don't retain it at any point. The the NIB loader should own the object, right?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload