Re: Memory management of NSStrings
Re: Memory management of NSStrings
- Subject: Re: Memory management of NSStrings
- From: Will Mason <email@hidden>
- Date: Sun, 10 Apr 2005 05:01:09 -0700 (PDT)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Every time you send a message like [rpt stringByAppendingString:
objectString] you are not required to worry about releasing the
resulting string; they are all the responsibility of the object to
which you are sending the message. Basically the rules are that if you
did not create an object using alloc, new or copy (or some variant of
any of the above), then you are not responsible for releasing it or for
worrying about when it might be ready to die.
Please refer to:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/index.html
I hope this helps,
Will
--- John James <email@hidden> wrote:
> I am still in my 1st year of learning so bear with me.
>
> I finally got this part of my program working, but I am not sure why.
> I have a method which creates a small report in a NSString* which is
>
> later
> shown in a window.
>
> I do something like this:
>
> NSString* rpt = @"#session( \r";
>
> and then multiple lines of the sort:
>
> rpt = [rpt stringByAppendingString : objectString];
> where objectString is built up in a similar way to make an report
> record.
>
> finally I return rpt.
>
> However it seems from my reading I should give a "[rpt autorelease]"
>
> before I return,
> but if I do I get a double release error. I can not find anything in
>
> the
> documentation or my many books explaining how rpt gets into the
> autorelease pool
> automatically, but I guess it does. And I probably missed it. Could
>
> someone give me
> a reference or a general rule when this happens.
_______________________________________________
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