Re: Glueing strings together...
Re: Glueing strings together...
- Subject: Re: Glueing strings together...
- From: "Laurent Daudelin" <email@hidden>
- Date: Tue, 13 Jan 2004 10:24:02 -0500
On 13/01/04 10:07, "Michael Becker" <email@hidden> wrote:
>
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?
Remember that objects you create without specifically using 'alloc', 'copy'
or that you didn't send them 'retain' are autoreleased objects. When you
create them, their lifespan is limited as they are placed in an autorelease
pool. When control execution returns to the application object, all objects
in the autorelease pool receive a 'release' message. Those that get their
retain count down to 0 are deallocated.
In the code above, the string object returned by stringByAppendingFormat:
was not created using 'alloc' or 'copy' and was not sent a 'retain' message,
so you can assume that it will be safely deallocated without any leak.
Read the memory management section in the Cocoa doc.
-Laurent.
--
========================================================================
Laurent Daudelin Developer, Multifamily, ESO, Fannie Mae
mailto:email@hidden Washington, DC, USA
************************ Usual disclaimers apply ***********************
_______________________________________________
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.