Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MadDoc

macrumors 6502
Original poster
Apr 25, 2005
329
5
UK
Hi,

I am really new to Objective-C and Cocoa and have been teaching myself using "Programming in Objective-C" to good effect using Xcode 2 on Tiger.

I just upgraded to leopard (and thus Xcode 3) and something has happened and now I can't get any of my programs to run :confused:

I have been making "Foundation tools" (command line utilities) from the book. This is the code:

Code:
#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // insert code here...
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}

It compiles and "runs" successfully but doesn't display the little white command line window printing "Hello, World!". This is the same with using the printf command and if I use the scanf command then the app remains runing (according to Activity Monitor) but is not on the dock or on my screen?

What is different about this version of Xcode? How come everything stopped working???

Thanks,

MadDoc,
 

Nutter

macrumors 6502
Mar 31, 2005
432
0
London, England
Have you opened the Console window? Choose "Console" from the Run menu.

By the way, why are you draining your autorelease pool, rather than releasing it?
 

garethlewis2

macrumors 6502
Dec 6, 2006
277
1
Oi Nutter,

Sorry couldn't resist :)

drain seems to be default for XCode 3 now. Seems to work even if you aren't using gc.
 

MadDoc

macrumors 6502
Original poster
Apr 25, 2005
329
5
UK
Have you opened the Console window? Choose "Console" from the Run menu.

Thanks, that seems to work great.

BTW, is there anyway to enable this by default (the console window always used to display without me having to select console from the Run menu)?

As for using 'drain' I hadn't been - that was simply the empty foundation tool program :rolleyes:

Thanks,
 

Nutter

macrumors 6502
Mar 31, 2005
432
0
London, England
The console window is always used for output, it's just that you didn't have it open. I can't find any way to get it to open automatically when you run, so you should just leave it open.

Anyone know why the template is now using drain? I'm surprised by this. Apple's memory management documentation still uses release - in fact, it doesn't mention drain at all.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Anyone know why the template is now using drain? I'm surprised by this. Apple's memory management documentation still uses release - in fact, it doesn't mention drain at all.

The documentation says it "ultimately calls objc_collect_if_needed". So I'm assuming that function is what cleans up the pool.

Plus, in this instance, it probably doesn't matter if you don't even release/drain the pool since the process is exiting and the OS will clean up the memory anyways (that is why sometimes dealloc is never called - it is faster for the OS to remove the used memory itself).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.