views:

273

answers:

2
@implementation Level
@synthesize doors, rooms;
- (id) init
{
   self = [super init];
   if (self != nil) {
      rooms = [[NSMutableArray alloc] init];
      doors = [[NSMutableArray alloc] init];
   }
   return self;
}


- (void)generate{
   int room_count = 2;
   Room *room; 
   for (int i=0; i<room_count; i++) {
     room = [[Room alloc] init];
     [room generate_Doors];
     [self.rooms addObject:room];
     [room release];
  }
  for (int i=0; i<[rooms count]; i++) {
    Room *r=[rooms objectAtIndex:i];
    //After this point rooms is invalid
    int l=[[r doors] count];
    for (int j=0; j<l; j++) {
        Door *d=[[[rooms objectAtIndex:i] doors] objectAtIndex:j];
        [self.doors addObject:d];
    }
  }

}

This is that i've seen in debugger

alt text

A: 

The debugging fragment you show does not indicate rooms is invalid, just that it is not displaying the values you expect - if you stop in the debugger after the loop and type in the debugger console:

po rooms

What does it display?

The code you have looks fine.

Kendall Helmstetter Gelner
A: 

The debug window does that sometimes. "Out of Scope" when it isn't.

Not much you can do about it, it's a bit of a bug in XCode. Just because the debugger can't show you the value in the window, doesn't mean the object is gone.

Have a read here on this stackoverflow.com question about debugging. It has some very nice debugging information. Good stuff to know!

nash