Re: NSImage initialization question
Re: NSImage initialization question
- Subject: Re: NSImage initialization question
- From: Julien Jalon <email@hidden>
- Date: Mon, 5 Nov 2001 23:20:00 +0100
Le lundi 5 novembre 2001, ` 09:48 PM, Dan Huntsinger a icrit :
- initObject
{
if (self = [super init])
{
/* class-specific initialization goes here */
NSString *title;
title = [[NSBundle mainBundle]
pathForImageResource:@"aSrcImage"];
theImage = [[NSImage alloc] initWithContentsOfFile:title];
// [title release]; // causes crash "EXC_BAD_ACCESS"
// [title autorelease]; // causes crash "EXC_BAD_ACCESS"
}
return self;
}
[...]
I understand that when I release title, I get the error because later
on, it
is trying to access the "title" string which no longer exists. I
thought
that "autorelease" might solve it but that doesn't work either. Can
anyone
explain to me (better than apple's docs do) how images are initialized
and
used, and why I need to keep the "title" string around for longer than
this
method.
title and theImage are autoreleased. See:
<
http://www.stepwise.com/Articles/Technical/MemoryManagement.html>
--Julien