UIImage imageNamed not autoreleasing correctly
Posted
by MrHen
on Stack Overflow
See other posts from Stack Overflow
or by MrHen
Published on 2010-05-28T15:15:50Z
Indexed on
2010/05/28
15:22 UTC
Read the original article
Hit count: 361
For some reason, the retain/release behavior in the following code has me completely baffled.
selectedImage = [UIImage imageNamed:@"icon_72.png"];
[selectedImage release];
This should break but does not. Why? I thought imageNamed
autoreleased itself which means the release here is redundant and should break when the autorelease occurs.
Here are snippets relevant to selectedImage from the .h and .m files:
@property (nonatomic, readonly) UIImage *selectedImage;
@synthesize delegate, selectedImage, spacerBottom, currentIndex;
Other notes, this does break:
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”.
As does this:
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”.
And so does the following:
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”.
And so does this:
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”.
© Stack Overflow or respective owner