Re: Re Re: String variables in classes
Re: Re Re: String variables in classes
- Subject: Re: Re Re: String variables in classes
- From: Graham Cox <email@hidden>
- Date: Mon, 3 Jan 2011 11:38:58 +1100
On 03/01/2011, at 10:17 AM, Brian Durocher wrote:
> This line of code seems to work for exactly what I was looking for:
>
> temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
> retain];
Except it's quite wrong from a memory management point of view.
As well as the excellent advice you've already received, you really must take my advice about not just reading but KNOWING the memory management rules:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
C++, with which you're familiar, has no built-in memory management except allocation and free. You have to track those allocations yourself if you are to prevent leaks and so on. In Cocoa, this tracking is about 80% handled for you provided you follow the rules. The rules are there to ensure that the tracking works. (Or you can enable garbage collection and then the tracking is 100% handled for you).
> although I have to admit I am unsure really what the "retain" will
> actually do here with respect to memory.
Which means you haven't read the rules, let alone committed them to heart. I urge you to do so before progressing further.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden