advertisement

Article:
  Creating Toolbars for Mac OS X
Subject:   Small error in setupToolbar method
Date:   2004-07-13 14:07:24
From:   krishengreenwell
Response to: Small error in setupToolbar method

Pardon... now there's an error with my error report. The code listed was the *incorrect* code, not the corrected version. It should have read:


---------------------------------
As mentioned here:
http://www.cocoadev.com/index.pl?NSToolbarSampleCode


...there's a small error with the provided setupToolbar method:


- (void)setupToolbar
{
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
[toolbar autorelease]; // wrong
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration:YES];
[mainWindow setToolbar:[toolbar autorelease]];
}


As you can see, there is a double autorelease, which is incorrect; it will cause the program to crash. The first autorelease call should be removed.
---------------------------------