Re: Need to release "constant objects"?
Re: Need to release "constant objects"?
- Subject: Re: Need to release "constant objects"?
- From: Julien Dufour <email@hidden>
- Date: Fri, 7 May 2004 02:13:29 +0200
On May 5, 2004, at 1:48, Jerry Krinock wrote:
Hello
I use these things I call "constant objects", mostly strings, that I
assign
to other variables, as needed, in a particular class. So, I declare
them as
globals at the top of the file like this (I show NSNumbers instead of
NSStrings as examples because the shorter lines fit better in email):
static NSNumber* objectTrue;
static NSNumber* objectFalse;
then I create them in my class's -init method:
objectTrue = [[NSNumber alloc] initWithBool:TRUE] ;
objectFalse = [[NSNumber alloc] initWithBool:FALSE] ;
and then I just assign to other variables whenever needed.
It looks like you are leaking here. You lack some test regarding a
previous initialization (you can't even make some decent test here
since you are not setting your variables to nil) or you will leak every
time the -init method is called (which is likely to happen quite often
or you won't be tried to create reusable constants) except the first
time.
My personal advice is to move the initialization of the constants into
the +initialize method of the class. Hence, they would also be
available from the class methods without surprises, and your software
won't have to worry about them every time it wants to use them.
Jerry Krinock
San Jose CA USA
Best regards.
Julien Dufour
Inferiis -
http://www.inferiis.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.