RE: Glueing strings together...
RE: Glueing strings together...
- Subject: RE: Glueing strings together...
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Tue, 13 Jan 2004 11:12:06 -0500
As others have pointed out, componentsJoinedByString is really what you want
for this particular situation. As for your actual query, whether there's a
leak depends on how you set up myString before you got to the loop. If you
initialized it with alloc/init (and didn't autorelease it before the loop)
you'll leak. That string object never gets released. If you initialized it
with a class method, like stringWithCapacity:, you won't. That object is
not your responsibility to release.
All the strings you create (and discard) in your loop are autoreleased, so
there's no problem there.
Jonathan
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Michael Becker
>
Sent: Tuesday, January 13, 2004 10:07 AM
>
To: email@hidden
>
Subject: Glueing strings together...
>
>
>
Hi!
>
>
I have a loop in which I need to glue strings together. Like this:
>
>
for (i=0; i<[ theArray count]; i++) {
>
myString = [ myString stringByAppendingFormat:"\n%@", [ theArray
>
objectAtIndex:i]];
>
}
>
>
This works well. My only concern is memory leaking. I am creating a new
>
string and setting my pointer to this new string, but does the old
>
(original) string get released?
>
What is the proper way to build a string out of many parts?
>
>
- Michael
>
_______________________________________________
>
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.
_______________________________________________
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.