views:

15

answers:

1

I'm in deep trouble. Something in my app causes a lot of properties in my app delegate to become trashed (changing contents and even object type, say an NSArray becomes an NSString...), and I can't debug it out. I can find no memory leaks or errors on my part. The only thing I've found is that all the way to ViewDidAppear for the view of the first tab, everything is okay. The view displays a table. When one of the cells are clicked, the app delegate properties are already trashed.

What after a view has been loaded and before didSelectCellForRow could cause this? No other code of mine is being executed between those two, certainly no code in the app delegate.

Any tips for hunting this down in an sleuthy manner would be appreciated, or just some thoughts on narrowing it down to what could cause it.

A: 

It sounds like either something is getting released prematurely or things are not properly connected with respect to one of your XIBs. If you haven't already, you might want to familiarize yourself with NSZombieEnabled, NSDeallocateZombies, NSEnableAutoreleasePool and NSAutoreleaseFreedObjectCheckEnabled. These are environment variables that can be set in the Executable "Get Info" window's Arguments panel.

For sanities sake, I have added this to my AppDelegate's -applicationDidFinishLaunching:

#ifdef DEBUG
//  account for environment value's actual value if set.
NSString *NSZombieEnabled = (getenv("NSZombieEnabled")) 
                                ? [NSString stringWithCString:getenv("NSZombieEnabled") encoding:NSASCIIStringEncoding] 
                                : @"NO";
DLog(@"NSZombieEnabled = %@", NSZombieEnabled );
NSString *NSDeallocateZombies = (getenv("NSDeallocateZombies")) 
                                ? [NSString stringWithCString:getenv("NSDeallocateZombies") encoding:NSASCIIStringEncoding] 
                                : @"NO";
DLog(@"NSDeallocateZombies = %@", NSDeallocateZombies );
NSString *NSEnableAutoreleasePool = (getenv("NSEnableAutoreleasePool")) 
                                ? [NSString stringWithCString:getenv("NSEnableAutoreleasePool") encoding:NSASCIIStringEncoding] 
                                : @"YES";
DLog(@"NSEnableAutoreleasePool = %@", NSEnableAutoreleasePool );
NSString *NSAutoreleaseFreedObjectCheckEnabled = (getenv("NSAutoreleaseFreedObjectCheckEnabled")) 
                                ? [NSString stringWithCString:getenv("NSAutoreleaseFreedObjectCheckEnabled") encoding:NSASCIIStringEncoding] 
                                : @"NO";
DLog(@"NSAutoreleaseFreedObjectCheckEnabled = %@", NSAutoreleaseFreedObjectCheckEnabled );

endif

It sometimes saves me from having to check these variables through Xcode UI.

westsider