Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you need to release them, but you need them just a little longer than beyond the end of your function.</p> <p>The solution is called <code>autorelease</code>. Just replace <code>release</code> with <code>autorelease</code> and the objects stay around until the program gets back to the runloop.</p> <p>When the program gets back there, everybody interested in one of the objects should have sent a <code>retain</code> message to it, so the object will not be deallocated when released by the <code>NSAutoreleasePool</code>.</p> <p><strong>edit</strong> actually, looking at your code, there's a lot more wrong with it. E.g. this:</p> <pre><code>UIButton *placeHolderButton = [[UIButton alloc] init]; placeHolderButton = sender; </code></pre> <p>doesn't make sense. First you allocate an object, then assign (a pointer to) it to variable <code>placeHolderButton</code>. That's fine.</p> <p>Then you assign <code>sender</code> to that same variable. The reference to the object you just created is now lost.</p> <p>Not sure if I get what you want, but this would be better:</p> <pre><code>-(IBAction)inputNumbersFromButtons:(id)sender { UIButton *placeHolderButton = sender; // this is still a little useless, but ok int i = placeHolderButton.tag; NSString *addThisNumber = [NSString stringWithFormat:@"%i", i]; NSString *placeHolderString = firstValue.text; NSString *newLabelText = [placeHolderString stringByAppendingString:addThisNumber]; [firstValue setText:newLabelText]; } </code></pre> <p>No allocs, so no releases necessary. The strings returned by those functions are already added to the autoreleasepool, so they will be deallocated automatically (if needed).</p>
 

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