"Gregory Weston" <uce@[EMAIL PROTECTED]
> wrote in message
news:uce-8DC145.20121117052008@[EMAIL PROTECTED]
> In article <6991f3F30747bU1@[EMAIL PROTECTED]
>,
> "Aaron Gray" <ang.usenet@[EMAIL PROTECTED]
> wrote:
>
>> Hi,
>>
>> I am trying to learn to program in Objective-C and Cocoa, still getting
>> the
>> basics though.
>>
>> What I want to know about is memory management.
>>
>> If I have the following program :-
>>
>> int main( int argc, char *argv[])
>> {
>> NSFileHandle *stdout = [NSFileHandle fileHandleWithStandardOutput];
>>
>> NSString *test = [NSString stringWithCString: argv[0]];
>>
>> Char *cstring = [test UTF8String];
>>
>> [stdout writeData: [NSData dataWithBytes: cstring length: strlen(
>> cstring)];
>>
>> [stdout fileClose];
>>
>> [test autorelease]
>>
>> return 0;
>> }
>>
>> I am getting messages saying "autoreleased with no pool in place".
>>
>> How do I go about creating a pool if thats what I need to do ?
>>
>> Otherwise how do I do the memory management.
>
> You found the answer to the question you asked, I see, but there are
> some issues in the above code. The biggest one is that your variable
> 'test' is already autoreleased. The second-to-last line in your code is
> redundant and an excellent habit into which to not get.
>
> Read this (very short) page:
>
>
<http://developer.apple.com/do***entation/Cocoa/Conceptual/MemoryMgmt/Tas
> ks/MemoryManagementRules.html>
>
> And this (longer) one:
>
>
<http://developer.apple.com/do***entation/Cocoa/Conceptual/CocoaFundament
> als/CocoaObjects/chapter_3_section_5.html>
Okay, yes, I found that out the hardway. I'll have a look at the
do***entation tommorow, its late here now.
Thanks alot,
Aaron


|