NSDictionary dictionaryWithContentsOfFile in Carbon app
NSDictionary dictionaryWithContentsOfFile in Carbon app
- Subject: NSDictionary dictionaryWithContentsOfFile in Carbon app
- From: Roni Music <email@hidden>
- Date: Sun, 8 Oct 2006 09:52:13 +0200
Hi,
I have a Carbon application and I have just added my first Cocoa
stuff and have a couple of questions relating to have memory is
deallocated.
Everything seems to work fine but I'm curious if I'm doing things
correctly (I'm a newbie with Obj-C and Cocoa).
Basically I use
NSDictionary *aDictionary = [NSDictionary
dictionaryWithContentsOfFile:[aString stringByExpandingTildeInPath]];
NSArray *anArray = [aDictionary objectForKey: @"aKey"];
and they are called from a member function in a C++ class
Here is what I do:
class foo
{
public:
foo();
~ foo();
void bar(); // this function will be called several times
private:
NSDictionary * aDictionary;
NSArray * anArray;
NSAutoreleasePool *pool;
};
foo:: foo()
{
aDictionary = 0;
anArray = 0;
pool = [[NSAutoreleasePool alloc] init];
}
CItunesImportDialog::~CItunesImportDialog()
{
[ aDictionary release];
[ anArray release];
[pool release];
}
// this function will be called several times
void foo::bar()
{
.....
[aDictionary release]; // ???
aDictionary = [NSDictionary dictionaryWithContentsOfFile:[aString
stringByExpandingTildeInPath]];
[aDictionary retain]; // ???
[anArray release]; // ???
anArray = [aDictionary objectForKey: @"aKey"];
[anArray retain]; // ???
......
//now use the array
}
So my question is:
Will the memory that is allocated by the aDictionary and anArray be
released when my destructor call [pool release];
if not, when does this happen?
also, is my use of retain and release correct - without it crashes so
it seems so?
Thanks for any comments/explanations
Rolf
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden