Re: How can I release an NSString?
Re: How can I release an NSString?
- Subject: Re: How can I release an NSString?
- From: j o a r <email@hidden>
- Date: Sun, 19 Jan 2003 10:58:55 +0100
This code will not leak memory because "stringWithString:" returns an
autoreleased object.
Read the documentation:
"It is possible for you to obtain a new object by invoking a class
method of the form +className.... These class convenience methods
create a new instance of the class, initialize it, and return it for
you to use. Although you might think you are responsible for releasing
objects created in this manner, that is not the case. Because the
class method allocates the memory for the object, it is responsible
for releasing that memory, thus class convenience methods should
return their values autoreleased."
<file:///Developer/Documentation/Cocoa/TasksAndConcepts/
ProgrammingTopics/MemoryMgmt/Concepts/ObjectOwnership.html>
j o a r
On Sunday, Jan 19, 2003, at 10:11 Europe/Stockholm, Arthur VIGAN wrote:
I have a quite simple question, which I find annoying...
Let's consider the following method:
- (NSString *)giveMeAString
{
NSString *aString;
aString = [NSString stringWithString:@"Hello World!"];
return aString
}
My question is: is memory leaking in this code, because the string is
never released? Should I use autorelease?
Thanks in advance for your answers to this basic question,
_______________________________________________
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.