0
@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 http://img163.imageshack.us/img163/8090/20091117174111.png

Abizern
  • 146,289
  • 39
  • 203
  • 257
Vladimir
  • 7
  • 3
  • I think you are misinterpreting the results you are getting from the debugger. Do some NSLog-debugging to make sure. e.g. add the following line below your comment: NSLog(@"are we still having something in our list - lets see the object-count %d", [rooms count]); – Till Nov 16 '09 at 16:16
  • For that matter, try `NSLog(@"First object: %@", [rooms objectAtIndex:0]);`. – Peter Hosey Nov 16 '09 at 17:57

2 Answers2

0

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
  • 74,769
  • 26
  • 128
  • 150
0

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!

Community
  • 1
  • 1
nash
  • 2,181
  • 15
  • 16