Re: Inconsistent Memory Management Rules
Re: Inconsistent Memory Management Rules
- Subject: Re: Inconsistent Memory Management Rules
- From: publiclook <email@hidden>
- Date: Tue, 15 Apr 2003 20:11:33 -0400
On Tuesday, April 15, 2003, at 07:24 PM, Denis Stanton wrote:
On Wednesday, April 16, 2003, at 08:32 AM, alex wrote:
// take date from words array
NSString *myDateString = [words objectAtIndex: 0];
int i;
for (i = 1; i < [words count]; i++) {
myDateString = [myDateString stringByAppendingString: @" "];
myDateString = [myDateString stringByAppendingString: [words
objectAtIndex: i]];
}
Thank you for your time
Denis
_______________________________________________
Your example does not leak. You didn't allocate or retain anything in
the example so you don't have to release or autorelease anything.
Cocoa's memory management conventions are that simple.
How about the one line solution:
NSString *totalDateString = [words componentsJoinedByString:@" "];
It's so much simpler.
If you want to keep totalDateString around, you need to retain it. If
you retain it, you will eventually need to release it.
I am curious why you didn't use -componentsJoinedByString: since you
mention it in your post and therefore must know of its existence.
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSArray.html
<Quote>
- (NSString *)componentsJoinedByString:(NSString *)separator
Constructs and returns an NSString that is the result of interposing
separator between the elements of the receivers array. For example,
this code excerpt writes the path System/Developer to the console:
NSArray *pathArray = [NSArray arrayWithObjects:@"System",
@"Developer", nil];
NSLog("The path is /%@.\n",
[pathArray componentsJoinedByString:@"/"]);
Each element in the receivers array must handle description. If the
receiver has no elements, an NSString representing an empty string is
returned.
See Also: componentsSeparatedByString: (NSString)
<End Quote>
_______________________________________________
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.