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

BadWolf13

macrumors 6502
Original poster
I've got an issue in a program that uses multiple windows and multiple XIB files. I'm pretty sure this has something to do with ARC, since I used the same code for similar programs back in the days of Garbage Collection, and it worked.

Basically, I create and initialize an instance of my NSWindowController subclass like so:

Code:
        CLProjectWindowController *__strong newWindowController = [[CLProjectWindowController alloc] initWithProject:selectedProject inManagedObjectContext:_managedObjectContext];
        [windowControllers addObject:newWindowController];

And I created a custom initializer in my custom window controller that goes like this:

Code:
- (id)initWithProject:(CLProject *)aProject inManagedObjectContext:(NSManagedObjectContext *)moc {
	if (!(self = [super initWithWindowNibName:@"Project"])) return nil;
    [self setProject:aProject];
    [self setManagedObjectContext:moc];
    
    [self showWindow:self];

    return self;
}

As I said above, I'm sure this has something to do with ARC since similar code worked perfectly fine before ARC was implemented. It's probably a weak reference somewhere, but I'm just not sure where. I declared my window controller array as __strong, but that didn't change anything. Is there any way in the debugging process to see what references, and how many, an object has? Anyone got any ideas where the weak reference is?
 
Ok, I feel silly now. I just added

Code:
    windowControllers = [[NSMutableArray alloc] init];

to the init method of my AppDelegate, and it works just fine now.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.