Note that there are some explanatory texts on larger screens.

plurals
  1. POUIImage imageNamed not autoreleasing correctly
    primarykey
    data
    text
    <p>For some reason, the retain/release behavior in the following code has me completely baffled.</p> <pre><code>selectedImage = [UIImage imageNamed:@"icon_72.png"]; [selectedImage release]; </code></pre> <p>This <em>should</em> break but <strong>does not</strong>. Why? I thought <code>imageNamed</code> autoreleased itself which means the release here is redundant and should break when the autorelease occurs.</p> <p>Here are snippets relevant to selectedImage from the .h and .m files:</p> <pre><code>@property (nonatomic, readonly) UIImage *selectedImage; @synthesize delegate, selectedImage, spacerBottom, currentIndex; </code></pre> <p>Other notes, this <strong>does</strong> break:</p> <pre><code>selectedImage = [UIImage imageNamed:@"icon_72.png"]; [selectedImage release]; [selectedImage release]; //objc[55541]: FREED(id): message release sent to freed object=0x59245b0 //Program received signal: “EXC_BAD_INSTRUCTION”. </code></pre> <p>As <strong>does</strong> this:</p> <pre><code>selectedImage = [UIImage imageNamed:@"icon_72.png"]; [selectedImage release]; [selectedImage autorelease]; //objc[55403]: FREED(id): message autorelease sent to freed object=0x59b54c0 //Program received signal: “EXC_BAD_INSTRUCTION”. </code></pre> <p>And so <strong>does</strong> the following:</p> <pre><code>selectedImage = [UIImage imageNamed:@"icon_72.png"]; [selectedImage autorelease]; [selectedImage release]; //objc[55264]: FREED(id): message release sent to freed object=0x592c9a0 //Program received signal: “EXC_BAD_INSTRUCTION”. </code></pre> <p>And so <strong>does</strong> this:</p> <pre><code>selectedImage = [UIImage imageNamed:@"icon_72.png"]; [selectedImage autorelease]; [selectedImage autorelease]; //objc[55635]: FREED(id): message release sent to freed object=0x5b305d0 //Program received signal: “EXC_BAD_INSTRUCTION”. </code></pre>
    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.
 

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