Ah, sorry, I didn't see that the code was in the original mail.

On 29 Nov 2010, at 06:07, [email protected] wrote:

> #import <Foundation/Foundation.h>
> int main(int argc, const char * argv[])
> 
> {
>       NSAutoreleasePool * Pool = [NSAutoreleasePool alloc] init];

You might find it helpful to use an editor (e.g. vim) that can show mismatched 
brackets.  It will easily help spot this kind of error.

>       NSLog (@"programming is fun");
>       [pool drain];

I know that the Apple examples all do this, but this is a really stupid idiom.  
Adding the [pool drain] line to the end of main() makes sure that all of your 
temporary objects are destroyed before the program exists.  This is a complete 
waste of CPU cycles - the OS will reclaim their memory (without needing to swap 
it back in if it's been swapped out) when the process exits and you should 
never rely on -dealloc/-finalize being called on an object.  

You also have an error here because you create a variable called Pool then send 
a message to pool (not the same - C is case sensitive).  This whole thing would 
be better written as:

        [NSAutoreleasePool new];
        NSLog(@"Programming is fun");
        return 0;

David
_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to