Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Short Answer:</strong></p> <p>Your code seems fine. The basic rule of thumb is that for every <code>alloc</code>, <code>new</code>, <code>retain</code>, or <code>copy</code>, you need a <code>release</code> or <code>autorelease</code>.</p> <hr> <p><strong>Long Answer:</strong></p> <p>Let's go through your code line by line.</p> <pre><code>UIImage *circleImage = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"item-circle" ofType: @"png"]]; </code></pre> <p>This first line uses a convenience method. you don't need to call release on anything, since you haven't called <code>alloc</code>, <code>new</code>, <code>retain</code>, or <code>copy</code>.</p> <pre><code>UIImageView *circleImageView = [[[UIImageView alloc] initWithImage: circleImage] autorelease]; </code></pre> <p>In the second line, you call <code>alloc</code>, but you then call <code>autoerelease</code>, so you're good there.</p> <pre><code>[imageView setFrame: CGRectMake(-5, -5, 65, 65)]; </code></pre> <p>Again, no <code>alloc</code>, <code>new</code>, <code>retain</code>, or <code>copy</code>.</p> <pre><code>UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom]; </code></pre> <p>Once again, you've used a convenience method. </p> <pre><code>[button addSubview: circleImageView]; </code></pre> <p>You still haven't called <code>alloc</code>, <code>new</code>, <code>retain</code>, or <code>copy</code>. Therefore, you don't call <code>release</code> or <code>autorelease</code>.</p>
    singulars
    1. This table or related slice is empty.
    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