Talk About Network

Google





Mac > Mac Programmer Help > Re: memory (de)...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 3742 of 3889
Post > Topic >>

Re: memory (de)allocation in a command line Cocoa application

by "Aaron Gray" <ang.usenet@[EMAIL PROTECTED] > May 18, 2008 at 01:21 AM

"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
 




 5 Posts in Topic:
memory (de)allocation in a command line Cocoa application
"Aaron Gray" &l  2008-05-17 22:36:33 
Re: memory (de)allocation in a command line Cocoa application
"Aaron Gray" &l  2008-05-17 23:24:20 
Re: memory (de)allocation in a command line Cocoa application
"Aaron Gray" &l  2008-05-18 00:23:32 
Re: memory (de)allocation in a command line Cocoa application
Gregory Weston <uce@[E  2008-05-17 20:12:11 
Re: memory (de)allocation in a command line Cocoa application
"Aaron Gray" &l  2008-05-18 01:21:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 19:26:41 PST 2009.