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 4 of 5 Topic 3742 of 3889
Post > Topic >>

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

by Gregory Weston <uce@[EMAIL PROTECTED] > May 17, 2008 at 08:12 PM

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>

-- 
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
   - Harry Potter and the Odor of the Phoenix
 




 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:25:37 PST 2009.