Hi all!
I've done a little cocoa programming before in tiger, and wrote a simple program to manage smileys, it had a few bugs, and some memory leaks! So I decided to rewrite it from scratch in objc2 and use garbage collection, and in process learn to use, and use core-animation and ... in my code.
Well, now before I even start I hit a problem. I have this code in my controller class to show an icon in status bar.
the problem is, with GC disabled, everything is working properly, but with GC enabled, the icon just flashes once and is gone, as if GC already destroyed my object. By stepping through code, I found out this is actually happening, the moment awakeFromNib finishes, theItem will be freed!
on a side note, I do retain theItem with GC disabled, but when GC is enabled, documentation says it's not needed, as it doesn't do anything.
any help would be appreciated!
I've done a little cocoa programming before in tiger, and wrote a simple program to manage smileys, it had a few bugs, and some memory leaks! So I decided to rewrite it from scratch in objc2 and use garbage collection, and in process learn to use, and use core-animation and ... in my code.
Well, now before I even start I hit a problem. I have this code in my controller class to show an icon in status bar.
Code:
@interface Controller : NSObject {
NSStatusItem* theItem;
IBOutlet NSMenu *StatusItemMenu;// Properly connected to a menu in IB
}
-(void)awakeFromNib;
@end
@implementation Controller
-(void)awakeFromNib
{
NSStatusBar *bar = [NSStatusBar systemStatusBar];
theItem = [bar statusItemWithLength:NSSquareStatusItemLength];
[theItem setHighlightMode:YES];
[theItem setImage:[NSImage imageNamed:@"MenuIcon"]];
[theItem setMenu:StatusItemMenu];
}
@end
the problem is, with GC disabled, everything is working properly, but with GC enabled, the icon just flashes once and is gone, as if GC already destroyed my object. By stepping through code, I found out this is actually happening, the moment awakeFromNib finishes, theItem will be freed!
on a side note, I do retain theItem with GC disabled, but when GC is enabled, documentation says it's not needed, as it doesn't do anything.
any help would be appreciated!